Reputation: 3391
This is about selenium webdriver in java. If clicking on an element, usually it goes fast but sometimes when server is busy it will say Connecting... at the top of the browser and hang. Usually to deal with waits, the code is: driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
but in this case when the server hangs on a click(), this doesn't throw an exception after the time limit, since the webdriver does not start counting until the click finishes connecting to the next url. Did anyone deal with this before, and how?
Is there a way to time completion of click()
and submit()
?
Upvotes: 8
Views: 12933
Reputation: 1361
Another option to those listed above is to use a timeout funtion within a execute_script call e.g.
setTimeout(function () {document.querySelector('#button').click() }, 1000);
This causes selenium to return immediately and click happens without hanging, because selenium doesn't know a click was called.
Upvotes: 0
Reputation: 21
When selenium hangs update your firefox version to be as updated as selenium
Upvotes: 1
Reputation: 578
The Selenium documentation states that Click() blocks. If for any reason, Selenium believes the page isn't completely loaded, then your Click will hang your test.
I've found that the easiest work-around is to completely skip the click event and use:
element.SendKeys(Keys.Enter);
instead. You get a two for one special - it doesn't block AND you're testing accessibility since many impaired users only use the keyboard to navigate anyway.
Upvotes: 6
Reputation: 38414
Yes, this is a known problem and as of Selenium 2.21.0, there is a way to go around.
The problem is that implicit wait is designed to wait for unloaded elements when you search for some, but the click()
method just waits until the browser states that the page is fully loaded.
Try driver.manage().timeouts().pageLoadTimeout()
which is a new method in 2.21.0 and should deal exactly with this.
Upvotes: 5