Can you click without waiting for the page to finish loading in Selenium Webdriver?

2,395 views
Skip to first unread message

robbiewinston

unread,
Sep 12, 2012, 12:03:47 PM9/12/12
to seleniu...@googlegroups.com
Hi,

I am testing a web page in which when a button is clicked, a new browser window is launched in which "window.print()" is included "onLoad", resulting in the Chrome print dialog appearing.

This is causing problems for my automated test (chrome via RemoteWebDriver).  The initial "click" request doesn't finish because the original page is waiting for the new window to load. If I manually close the print dialog (or press "ESC") then the test continues, without this manual intervention, then "click" timesout.

I am writing my test in C#, so have experimented with threading ;

Task.Factory.StartNew(() => _driver.FindElement(_submitButton).Click()).ContinueWith(a => finished = true);
....
...
_driver.Keyboard.SendKeys(Keys.Escape);

The send keys request is made despite the "Click" not finishing but also hangs as well.

Any ideas?

Thanks

robbiewinston

unread,
Sep 12, 2012, 12:09:19 PM9/12/12
to seleniu...@googlegroups.com
I've just tried an Action builder, still hangs on the click;

builder.MoveToElement(_driver.FindElement(_submitButton))
                .Click().Perform();


Mike Riley

unread,
Sep 12, 2012, 4:03:43 PM9/12/12
to seleniu...@googlegroups.com
If the page has not finished loading then the DOM is changing and your element reference may not be valid when you use it.

I generally test for the element being present and then I try and interact with it.  That works in most cases.  Where it does not I found that testing for the last element to appear on the page will generally do the trick.

Mike

robbiewinston

unread,
Sep 13, 2012, 4:19:24 AM9/13/12
to seleniu...@googlegroups.com
Hi Mike,

I think you may have misunderstood my problem.

1) Perform Click (ie.  _driver.FindElement(_submitButton).Click() )

2) The standalone hub server log shows the Click request has been executed but not yet finished

3) The click is peformed on the page

4) new browser is launched with "window.print()" resulting in a print dialog appearing in the new window

5) The hub server log shows that it is still waiting for a response to the click

6) The original web browser is "spinning" (ie. spinning logo)

7) Nothing happens until I close the print dialog in the new browser, at which point the hub server gets the "done" response.

8) I can fire other requests (by putting the "click" in a seperate thread) while the "Click" is "hanging", but these also hang.

I seem to be a bit stuffed!!  Interestingly other browsers don't wait for the dialog to close, it is only chrome.

Mike Riley

unread,
Sep 13, 2012, 2:56:00 PM9/13/12
to seleniu...@googlegroups.com
That may be a different behavior in that browser.  I would file an issue against the chrome driver then:
http://code.google.com/p/chromedriver/issues/list

You will want to include as much of the HTML and Selenium code as you can, or try creating a simple reproducible test case for them.

My one concern is that a print dialog is going to be a system dialog, which you would need something else to interact with, but still it should be returning from the click() method so you could do so.  It definitely sounds like a bug to me.

Mike

robbiewinston

unread,
Sep 14, 2012, 8:22:50 AM9/14/12
to seleniu...@googlegroups.com
Hi,

Yes, it looks like it's a known issue;

Issue 111:ChromeDriver hangs when submitting a form that opens a new tab

Which in turns looks like a bug in Chrome it self

Mike Riley

unread,
Sep 15, 2012, 7:38:34 PM9/15/12
to seleniu...@googlegroups.com
Then be sure and add yourself to the issue.  That way you get updates and they know more people are running into it.

Mike
Reply all
Reply to author
Forward
0 new messages