Are We Using Proper Wait In Proper Way In Selenium Webdriver?

Hello Folks,

We will see a very basic concept of waits in selenium. I have already covered waits in selenium in details. You can go through below link:

Wait in Selenium webdriver

Someday ago, one guy asked me that explicit wait is not working for him. Webdriver is not using wait time to find web element and throw NoSuchElementException. Given wait time is completely neglected by webdriver.

He has written code as below:

Explicit wait code:

It was throwing below exception:
Exception in thread “main” org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element

He tried so many things like version upgrade, different browsers , operating system as well but same behavior. I solved his problem and I thought to write a post on this.

Do we understand wait before using it in Selenium webdriver? If yes, you are excellent. If not, don’t worry, read this post.

Behavior of selenium webdriver is correct in above example. You are asking webdriver to wait till some web element is visible. Your are not instructing webdriver to wait till element is located and visible. In above wait condition (visibilityOf), webdriver expects that element is present in DOM and it will wait till its visibility. It will not wait if web element is not located. SO when webdriver does not locate webelement instantly, it throws NoSuchElementException in no time. It will not wait because wait time is set for visibility of web element not for locating web element.