Tuesday, January 29, 2013

WebDriver waits

Web application automation is depends on so many factors. Browser, network speed ...etc. We should write unquie code for running in all environments. For achieveing that we need to wait for WebElements before performing any operation on that.

Here we will see some built-in waits in WebDriver.


1WebDriver driver = new FirefoxDriver();
2driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
4WebElement myElement = driver.findElement(By.id("someId"));
Implicit waits are basically your way of telling WebDriver the latency that you want to see if specified web element is not present that WebDriver looking for. (Click here for more information). This will be useful when certain elements on the webpage will not be available immediately and needs some time to load.


1driver.manage().timeouts().pageLoadTimeout(30, SECONDS);
Sets the amount of time to wait for a page load to complete before throwing an error. If the timeout is negative, page loads can be indefinite.



Sets the amount of time to wait for an asynchronous script to finish execution before throwing an error.


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.