2

我在 Java 中使用 webdriver 和 firefox。我正在使用注释搜索元素,例如:

@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 等。但我想知道为什么它不显示选择器,我怎样才能摆脱那个警告?

谢谢!

4

1 回答 1

0

虽然这不是一个理想的解决方案,但它帮助我解决了同样的问题。

通过设置 webdriver 系统属性来启用对文件的日志记录,例如

-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

于 2013-07-24T15:24:23.820 回答