8

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()?

4 Answers 4

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Or use 1 of 4 things. Fluent Wait, pageLoadTimeOuts, implicit waits, or a runnable/ Future if in Scala. This is very case dependent.
Because not all of us know from selenium.webdriver.common.keys import Keys
5

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.

4 Comments

this works on firefoxdriver but not on chrome driver. most websites it works, but some it will take 10 seconds to throw the exception, even if timeout is 2 seconds which is still better than waiting 2 minutes.
I guess. For Chrome driver (and IEdriver, too), we'll just have to wait a little bit longer, it's a brand new method that didn't make it further than to FF. You know, Selenium 2 is still in vast development.
This makes it work always: FirefoxProfile fp = new FirefoxProfile(); fp.setPreference("webdriver.load.strategy", "unstable"); driver = new FirefoxDriver(fp); driver.manage().timeouts().pageLoadTimeout(4, TimeUnit.SECONDS);
I am having this issue and I tried your theory using Selenium 2.39 and Firefox 26 and it did NOT resolve the problem and not with Chrome 31 either.
1

When selenium hangs update your firefox version to be as updated as selenium

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.