Search code examples
javaseleniumwebdriver

Selenium, click on element, hangs


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


Solution

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