what's the equivalent of waitForPageLoad in webdriver

871 views
Skip to first unread message

shen xieyin

unread,
Sep 8, 2010, 5:09:43 AM9/8/10
to webdriver
Hi,

I am now doing a pilot work to migrate our test code from selenium1 to
selenium2, when I use findElement(By).click to find the target
element, which cause a page to reload or to load to a new page, so
what method can I call to wait for page load to be finished, just like
waitForPageLoad in Selenium interface originally?


Thanks,
-Jovi

hrushikesh amdekar

unread,
Sep 8, 2010, 9:51:03 AM9/8/10
to webd...@googlegroups.com
You dont need to use any wait for page load method. Driver instance you have created should take care of the page. Whenever a page is loaded completely then only it will perform further actions.,, However if you want to use any wait for page to load then you can design one with Thread.sleep(1000) method using a for loop and a break. However driver instance created in Webdriver takes care of page loading automatically.

Hope this helps.


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.


Jason Leyba

unread,
Sep 8, 2010, 11:57:04 AM9/8/10
to webd...@googlegroups.com
Just to clarify:  WebDriver.get() will block until the page has loaded - this corresponds to the firing of the onload event.  To make sure the elements you want to interact with are present on the page, you should use one of the wait mechanisms.  There are two possibilities:

1. Use implicit waits. Here the driver will wait up until the designated timeout until the element is found.  Be sure to read the javadoc for the caveats.  Usage:

  driver.get("http://www.google.com");
  driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
  WebElement element = driver.findElement(By.name("q"));
  driver.manage().timeouts().implicitlyWait(0, TimeUnit.SECONDS);
  // continue with test...

2. Use the org.openqa.selenium.support.ui.WebDriverWait class.  This will poll until the expected condition is true, returning that condition's result (if it's looking for an element).  This is much more flexible than implicit waits, as you can define any custom behavior.  Usage:

Function<WebDriver, WebElement> presenceOfElementLocated(final By locator) {
  return new Function<WebDriver, WebElement>() {
    public WebElement apply(WebDriver driver) {
      return driver.findElement(locator);
    }
  };
}
// ...
driver.get("http://www.google.com");
WebDriverWait wait = new WebDriverWait(driver, /*seconds=*/3);
WebElement element =
    wait.until(presenceOfElementLocated(By.name("q"));

-- Jason

hrushikesh amdekar

unread,
Sep 8, 2010, 12:07:30 PM9/8/10
to webd...@googlegroups.com
Thanks Jason

Just wondering if webdriverwait class is available with .net libraries of webdriver.. as i am using C# for doing automation.

However methods you have suggested looks interesting Thanks a lot!!!

shen xieyin

unread,
Sep 9, 2010, 4:38:19 AM9/9/10
to webdriver
thanks, but further question is you say that "Driver instance you
have
created should take care of the page. Whenever a page is loaded
completely
then only it will perform further actions" so what if -

1. sometimes when we play an action, it does not cause page reload,
what will the action (i.e. click) execute, will it automatically
defect the page status and take the right action or something else?
can you explain more internal details?

2. if webdriver can take care of the page load automatically, is there
a way to set the timeout for the page load wait time like selenium1.0?


-Jovi
> On Wed, Sep 8, 2010 at 6:51 AM, hrushikesh amdekar <hrush...@gmail.com>wrote:
>
>
>
> > You dont need to use any wait for page load method. Driver instance you
> > have created should take care of the page. Whenever a page is loaded
> > completely then only it will perform further actions.,, However if you want
> > to use any wait for page to load then you can design one with
> > Thread.sleep(1000) method using a for loop and a break. However driver
> > instance created in Webdriver takes care of page loading automatically.
>
> > Hope this helps.
>
> > On Wed, Sep 8, 2010 at 2:39 PM, shen xieyin <shenxie...@gmail.com> wrote:
>
> >> Hi,
>
> >> I am now doing a pilot work to migrate our test code from selenium1 to
> >> selenium2, when I use findElement(By).click to find the target
> >> element, which cause a page to reload or to load to a new page,  so
> >> what method can I call to wait for page load to be finished, just like
> >> waitForPageLoad in Selenium interface originally?
>
> >> Thanks,
> >> -Jovi
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "webdriver" group.
> >> To post to this group, send email to webd...@googlegroups.com.
> >> To unsubscribe from this group, send email to
> >> webdriver+...@googlegroups.com<webdriver%2Bunsubscribe@googlegroups .com>
> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/group/webdriver?hl=en.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "webdriver" group.
> > To post to this group, send email to webd...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > webdriver+...@googlegroups.com<webdriver%2Bunsubscribe@googlegroups .com>
> > .

Simon Stewart

unread,
Sep 9, 2010, 5:25:09 PM9/9/10
to webd...@googlegroups.com
On Thu, Sep 9, 2010 at 9:38 AM, shen xieyin <shenx...@gmail.com> wrote:
> thanks, but further question is you say that "Driver instance you
> have
> created should take care of the page. Whenever a page is loaded
> completely
> then only it will perform further actions" so what if -
>
> 1. sometimes when we play an action, it does not cause page reload,
> what will the action (i.e. click) execute, will it automatically
> defect the page status and take the right action or something else?
> can you explain more internal details?

Assume it doesn't block in those cases, and make use of the
WebDriverWait class and the matching Wait interface.

How it's implemented depends on the browser, but we tend to do some
basic checks before starting an action to see if it's a sensible thing
to do.

> 2. if webdriver can take care of the page load automatically, is there
> a way to set the timeout for the page load wait time like selenium1.0?

Adam Goucher has written about this recently:

http://element34.ca/blog/why-your-synchronization-method-doesnt-work-anymore

Regards,

Simon

> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.

shen xieyin

unread,
Sep 20, 2010, 8:35:34 AM9/20/10
to webd...@googlegroups.com
Thanks Simon and Jason, the custom wait works in my code now!

2010/9/10 Simon Stewart <simon.m...@gmail.com>

Daniel Perez

unread,
Aug 8, 2013, 4:18:58 PM8/8/13
to webd...@googlegroups.com
Hello your answer is very helpful for me and i have a question how can i get the time when load complete im using a start and finish time but ther is any other solution thanks
Reply all
Reply to author
Forward
0 new messages