Posted

2 minutes read

Here are details related to using waits with Selenium WebDriver in Java. According to the Selenium documentation, at the moment, there are two different type of waits: explicit and implicit.

After you understand how to locate elements with Selenium WebDriver, you have to focus on waiting for elements to appear, be visible, be clickable.

Waiting is an automated step, elapse a certain amount of time, before execution can continue. Choose to use Explicit Waits or Implicit Waits. As a side note, you should not mix implicit and explicit waits.

Implicit Waits in Selenium WebDriver

An implicit wait tells WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available.

The implicit wait is set for the life of the WebDriver object instance.


WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);


//use a URL that delays loading elements
driver.get("http://www.example.com/");
WebElement myDynamicElement = driver.findElement(By.id("myDynamicElement"));

You can set the implicit wait when you first instantiate the WebDriver:


 

LoadFocus.com is a cloud testing platform, use Automated Website Testing Service to build functional tests and automate regression manual tests of your website, more details.


Thanks for reading. I hope you learned something interesting about React!
If you found this article useful, please share it with others. Don’t forget to subscribe to get notified for the upcoming articles.