测试用例:testMethod耗时10.342秒 导致错误 无法单击元素(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:172毫秒 内部版本信息:版本:“2.23.1”,修订:“17143”,时间:“2012-06-08 18:59:04” 系统信息:os.name:“Windows 7”,os.arch:“x86”,os.version:“6.1”,java.version:'1.6.0_33' 驱动程序信息:Driver.version:RemoteWebDriver 会话ID:8dfc5072-2755-40a7-bb32-05708c51101f com.thinkworks.selenium。 SeleniumException:无法单击元素(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:172毫秒 内部版本信息:版本:“2.23.1”,修订:“17143”,时间:“2012-06-08 18:59:04” 系统信息:os.name:“Windows 7”,os.arch:“x86”,os.version:“6.1”,java.version:“1.6.0_33” 驱动程序信息:Driver.version:RemoteWebDriver 会话ID:8dfc5072-2755-40a7-bb32-05708c51101f 在org.openqa.selenium.internal.seleniumemulation上。 SeleneseCommand.apply(SeleneseCommand.java:41) 在org.openqa.selenium.internal.seleniumemulation上。 Timer.run(Timer.java:38) 在org.openqa.selenium上。 WebDriverCommandProcessor.execute(WebDriverCommand Processor.java:144) 在org.openqa.selenium上。 WebDriverCommandProcessor.doCommand(WebDriverCommand处理器.java:74) 在com.thoughtworks.selenium。 DefaultSelenium.click(DefaultSelinium.java:193) 在dmswebui。 IE.TestLogin.testMethod(TestLogin.java:19) 原因:org.openqa.selenium。 ElementNotVisibleException:无法单击元素(警告:服务器未提供任何堆栈跟踪信息) 命令持续时间或超时:172毫秒 内部版本信息:版本:“2.23.1”,修订:“17143”,时间:“2012-06-08 18:59:04” 系统信息:os.name:“Windows 7”,os.arch:“x86”,os.version:“6.1”,java.version:'1.6.0_33' 驱动程序信息:Driver.version:RemoteWebDriver 会话ID:8dfc5072-2755-40a7-bb32-05708c51101f 位于java.lang.reflect。 Constructor.newInstance(未知源) 在org.openqa.selenium.remote上。 ErrorHandler.createThrowable(错误处理程序.java:188) 在org.openqa.selenium.remote上。 ErrorHandler.throwIfResponseFailed(错误处理程序.java:145) 在org.openqa.selenium.remote上。 RemoteWebDriver.exexecute(RemoteWebDriver.java:458) 在org.openqa.selenium.remote上。 执行(RemoteWebElement.java:244) 在org.openqa.selenium.remote上。 RemoteWebElement.click(RemoteWebElement.java:77) 在org.openqa.selenium.internal.seleniumemulation上。 Click.handleSeleneseCommand(Click.java:36) 在org.openqa.selenium.internal.seleniumemulation上。 Click.handleSeleneseCommand(Click.java:1) 在org.openqa.selenium.internal.seleniumemulation上。 SeleneseCommand.apply(SeleneseCommand.java:32)
-
1 提供一个示例页面和示例代码,您可以在其中进行复制。 另请查看WebDriverWait,以确保它不是时间问题。 – 阿兰 2012年6月16日11:26
4个答案
原因:org.openqa.selenium。 ElementNotVisibleException:无法单击元素
-
一般情况下,您可以单击页面上的不可见元素。 如果您认为,单击发生得太早,在元素可能会暴露其自身之前,您应该等待元素变得可见,然后再单击。 使用标准Web驱动程序API没有其他方法可以解决这个问题。 – 阿什温·帕布 2012年6月18日9:45 -
您可以尝试使用JavascriptExecutor接口使用JavaScript执行单击操作,这肯定会奏效,因为您正在走出WebDriver沙箱,自己动手。 那应该是你最后的选择。 – 阿什温·帕布 2012年6月18日9:46 -
-
嘿,我用了一个变通方法。。。 如果我在考虑中的页面上等待一些文本,它就会起作用。 例如,在触发单击事件之前,我会执行waitForTextPresent,这会导致IE等待出现一些文本,然后再触发单击事件@ 阿什温:谢谢你的回答:) – 赫里希克什普19 2012年6月18日17:19 -
5 WebDriverWait wait=新WebDriverWait(webDriver,timeoutInMillis); wait.until(ExpectedConditions.visibilityOfElementLocated(By.id<locator>)); 或等待.until(ExpectedConditions.elementToBeClickable(By.id<locator>)); – 阿什温·帕布 2012年6月18日17:50
for(int second=0;;second++){ 如果(秒>=60)返回“页面加载失败”; 尝试{ if(session().isTextPresent(“注销”)) 断裂; } catch(异常e){} 线程休眠(1000); }
session().some命令
尝试{ button.click(); } 捕获(异常e) { 线程休眠(1000); }