Alternative to Thread.Sleep when using selenium webdriver

3,199 views
Skip to first unread message

Sean Chambers

unread,
Mar 17, 2010, 12:42:14 AM3/17/10
to webdriver
I recently started using selenium and picked up webdriver as it seems
much more stable and doesn't require a serverside counterpart to
automate in a continuous integration server.

Everything seems to be going fine, except for when I have a page that
has a fair amount of javascript to load. In these instances I find
myself doing Thread.Sleep(3000) a lot and the like. While this works,
it seems undesirable. Is there a better way to wait until all of the
javascript has finished loading, or after javascript redirects occur
to tell the webdriver to hold up for a moment?

My app has a large amount of javascript redirecting and processing
fields and as a result we often have things loading at startup.

If putting the thread to sleep is the best way then I will continue
down that path, just wondering if there was something similar to
waitForPageToLoad in webdriver land. Thanks

Sean Chambers

Eran M.

unread,
Mar 23, 2010, 7:13:37 AM3/23/10
to webd...@googlegroups.com
Hi,

The appropriate way would be to wait for a state of a page that indicates Javascript execution is done. The most trivial condition is presence of element or page title value. It's also possible to execute Javascript through the driver to inspect internal page state.
You can find code examples in previous discussions on this list:

Eran


--
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.


bill shelton

unread,
Mar 23, 2010, 10:53:22 AM3/23/10
to webdriver
For what it's worth, the below example is working for me. This is
based on the snippet Jason provided in response to a similar question
I had (http://groups.google.com/group/webdriver/browse_thread/thread/
9841f64ca61fe12c).

http://gist.github.com/341240

bill

On Mar 23, 7:13 am, "Eran M." <eran....@gmail.com> wrote:
> Hi,
>
> The appropriate way would be to wait for a state of a page that indicates
> Javascript execution is done. The most trivial condition is presence of
> element or page title value. It's also possible to execute Javascript
> through the driver to inspect internal page state.

> You can find code examples in previous discussions on this list:http://groups.google.com/group/webdriver/browse_thread/thread/9f28184...


> look up "wait" and see other discussions related to this).
>
> Eran
>

> On 17 March 2010 04:42, Sean Chambers <schamber...@gmail.com> wrote:
>
> > I recently started using selenium and picked up webdriver as it seems
> > much more stable and doesn't require a serverside counterpart to
> > automate in a continuous integration server.
>
> > Everything seems to be going fine, except for when I have a page that
> > has a fair amount of javascript to load. In these instances I find
> > myself doing Thread.Sleep(3000) a lot and the like. While this works,
> > it seems undesirable. Is there a better way to wait until all of the
> > javascript has finished loading, or after javascript redirects occur
> > to tell the webdriver to hold up for a moment?
>
> > My app has a large amount of javascript redirecting and processing
> > fields and as a result we often have things loading at startup.
>
> > If putting the thread to sleep is the best way then I will continue
> > down that path, just wondering if there was something similar to
> > waitForPageToLoad in webdriver land. Thanks
>
> > Sean Chambers
>
> > --
> > 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%2Bunsu...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages