Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Selenium: WebDriver: Waiting for webpage to load

While doing automation on Web Applications, you may face this kind of problem, where you are trying to find an Element, but page is not loaded fully, you may endup in NoSuchFrameException. Pagy may load slowly due to network issues (or) application issues, to handle these kind of situations, we need to wait until the page loaded fully (or) at least the web element we are looking for is loaded.

WebDriver.Timeouts interface provides following methods to set the time outs for complete page load, you can specify Amount of time the driver should wait when searching for an element if it is not immediately present, You can specify the amount of time to wait for an asynchronous script to finish execution before throwing an error. Following table summarizes the methods defined in WebDriver.Timeouts interface.

Method
Description
Timeouts implicitlyWait(long time, TimeUnit unit)
Specifies the amount of time the driver should wait when searching for an element if it is not immediately present. When searching for a single element, the driver should poll the page until the element has been found, or this timeout expires before throwing a NoSuchElementException.
Timeouts setScriptTimeout(long time, TimeUnit unit)
Sets the amount of time to wait for an asynchronous script to finish execution before throwing an error.
Timeouts pageLoadTimeout(long time, TimeUnit unit)
Sets the amount of time to wait for a page load to complete before throwing an error.

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


In my next post, I am going to explain about explicit time outs usage.



Previous                                                 Next                                                 Home


This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Selenium: WebDriver: Waiting for webpage to load

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×