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?

4

2 回答 2

4

我有同样的问题,这是由于加载页面没有足够的延迟

您可以使用以下命令增加加载页面的超时延迟

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

于 2013-12-11T21:35:50.400 回答
0

您的问题的可能解决方案:1)而不是 xPath 找到所需元素的 css 选择器。它会是这样的:

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

但在您在firepath中使用它之前,请先验证ffox中所需元素的firebug插件位置是否正确。

火路验证

在我们获得所需的 css 选择器后,我们可以使用始终有效的方法。使用将在所需元素上执行单击的 js 函数。

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());
}

希望这对你有用。

于 2012-09-27T10:44:43.910 回答