我在Java中使用带有firefox的webdriver。 我正在使用注释来搜索元素,例如:
@FindBy(id = "terminal")
private WebElement selectTerminal;
假设页面无法呈现,并且由于某种原因,此元素无法呈现。错误信息是非常模糊的,如果我在Jenkins上远程运行测试,它很难调试,看看究竟发生了什么,例如:
The element could not be found (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 72 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.20.0', revision: '16008', time: '2012-02-28 15:00:40'
System info: os.name: 'Linux', os.arch: 'i386', os.version: '2.6.32-312-ec2', java.version: '1.6.0_20'
Driver info: driver.version: RemoteWebDriver
我怎样才能获得包含选择器的更详细信息?当然我可以用某种辅助方法包装它,使用try / catch等。但我想知道的是为什么它不显示选择器,我怎么能摆脱那个警告?
谢谢!
答案 0 :(得分:0)
虽然这不是一个理想的解决方案,但它帮助我解决了同样的问题。
通过设置webdriver系统属性E.g。
启用日志记录-Dwebdriver.firefox.logfile=/tmp/ff.log
或在您的测试代码中:
System.setProperty("webdriver.firefox.logfile", "/tmp/ff.log")
然后在ff.log中你应该看到错误发生的输出,例如
[6.389][FINE]: Command received (/session/5a4c8a0a7ef5453467687267348e8cb3/element) with params {
"using": "xpath",
"value": "//input[@class='login-submit']
}
[6.389][FINER]: Waiting for all views to stop loading...
[6.390][FINER]: Done waiting for all views to stop loading
[6.505][FINER]: Waiting for all views to stop loading...
[6.506][FINER]: Done waiting for all views to stop loading
[6.506][WARNING]: Command finished (/session/5a4c8a0a7ef5453467687267348e8cb3/element) with response {
"sessionId": "5a4c8a0a7ef5453467687267348e8cb3",
"status": 7,
"value": {
"message": "The element could not be found"
}
}
至少现在我可以看到它基于 xpath 的元素。这也适用于ChromeDriver