1

One of my Selenium tests issues a click on a button to create a new user:

seleniumDriver.findElement(By.xpath("//input[@value='Save']")).click();

However, the validation fails (it is meant to fail!) so that a <div> is displayed to inform the user to correct some input fields. This works very well manually, but the automated test aborts with the following error message:

com.thoughtworks.selenium.SeleniumException: Timed out waiting for action to finish
    at org.openqa.selenium.internal.seleniumemulation.Timer.run(Timer.java:44)
    at org.openqa.selenium.WebDriverCommandProcessor.execute(WebDriverCommandProcessor.java:145)
    at org.openqa.selenium.WebDriverCommandProcessor.doCommand(WebDriverCommandProcessor.java:75)
    at com.thoughtworks.selenium.DefaultSelenium.click(DefaultSelenium.java:193)
    at com.holcim.logon.admin.web.admin.UserTest.createUser(UserTest.java:354

How is it possible that a click() ends up in a timeout? And how could I possible fix this?

dokaspar
  • 8,186
  • 14
  • 70
  • 98
  • What webdriver are you using? If it's Chrome, when it clicks the button, have a look in the Chrome Developer tools to see if anything is still being fetched. – Arran Sep 26 '12 at 18:07
  • I am using Firefox, not Chrome. – dokaspar Sep 26 '12 at 18:55
  • I found this helpful: https://stackoverflow.com/questions/15268255/selenium-webdriver-throws-timeout-exceptions-sporadically – caznew May 31 '17 at 14:31

2 Answers2

4

I had the same problem, and It was due to not enough delay for loading page

You can increase timeout delay for loading page using following command

driver.Manage().Timeouts().SetPageLoadTimeout(new TimeSpan(0,0,0,0,timespan));

Sali Hoo
  • 743
  • 2
  • 8
  • 22
0

possible solution to your problem: 1) instead of xPath find css selector of the needed element. it gonna be something like:

String cssSelector = "input[value='Save']";

but before you gonna use it verify in firepath, firebug addon in ffox that needed element is located properly.

firepath verify

After we obtained needed css selector, we can use approach that always works. using js function that will perform a click on the needed element.

public void jsClick(String cssSelector){
JavascriptExecutor js = (JavascriptExecutor) driver;
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("var x = $(\'"+cssSelector+"\');");
        stringBuilder.append("x.click();");
        js.executeScript(stringBuilder.toString());
}

Hope this works for you now.

eugene.polschikov
  • 7,254
  • 2
  • 31
  • 44