【发布时间】:2013-06-17 23:17:21
【问题描述】:
我是 Selenium 的新手,正在尝试使用 http://docs.seleniumhq.org/docs/03_webdriver.jsp 上的示例。但是,它不起作用。每次我运行它时,无论是从通过 Maven 的 JUnit 测试还是从 Eclipse Juno 作为 Java 应用程序,我都会得到如下信息:
Exception in thread "main" org.openqa.selenium.WebDriverException: Session not found: 1d1a9aa2-f089-4f36-bb05-e1505c7b4e85
Command duration or timeout: 28 milliseconds
Build info: version: '2.33.0', revision: '4ecaf82108b2a6cc6f006aae81961236eba93358', time: '2013-05-22 12:00:17'
System info: os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.6.0'
Session ID: 1d1a9aa2-f089-4f36-bb05-e1505c7b4e85
Capabilities [{handlesAlerts=true, rotatable=false, databaseEnabled=true, locationContextEnabled=true, acceptSslCerts=true, applicationCacheEnabled=true, cssSelectorsEnabled=true, nativeEvents=true, takesScreenshot=true, platform=XP, browserName=firefox, javascriptEnabled=true, version=17.0.6, webStorageEnabled=true, browserConnectionEnabled=true}]
Driver info: org.openqa.selenium.firefox.FirefoxDriver
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...
这是失败的代码:
public static void main(String[] args) {
// Create a new instance of the Firefox driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
WebDriver driver = new FirefoxDriver();
// And now use this to visit Google
driver.get("http://www.google.com"); // FAILURE
我通过它进行调试发现,当调用 FirefoxDriver 构造函数时,Firefox 窗口实际上在我的系统上打开,然后消失,然后再次打开。然后它在 driver.get() 调用上失败。
我搜索了这个网站,发现问题出在 Chrome 或 IE 上,但 Firefox 可以。其他一切似乎都是一个不同的错误。我试图从它打开的窗口中获取我的 Firefox 版本,但是当我选择“关于 Firefox”时,我得到的只是:
<window xmlns:html="http://www.w3.org/1999/xhtml"
^
如果我直接启动 Firefox,我会看到我的 Firefox 版本是 17.0.6,并显示“您当前在 esr 更新频道”。顺便说一句,保持该窗口打开也没有任何效果 - 它仍然会打开一个新的 Firefox 窗口,然后将其关闭、重新打开,然后将其留在那里。
【问题讨论】:
-
您的
etc/hosts文件中有任何条目吗?如果有任何其他绑定到 127.0.0.1 而非localhost,WebDriver 将失败。 -
您使用的 Selenium 版本可能与 Firefox17 不兼容。有考虑降级到FF12/13还是升级到FF19?您使用的是哪个版本的 Selenium?
-
Slanec - 实际上,我的 hosts 文件中确实有第二个 127.0.0.1 条目。但是,删除它没有任何区别。进行更改后是否需要重新启动 Win 7?
-
Sri,我使用的是 Selenium 2.33。这个版本的FF是我公司规定的,所以改版不是我可以轻易做的。
-
删除额外的 etc hosts 行后重新启动没有任何区别。另外,我有一个同事安装了相同级别的 FF,但它在 Linux 上,完全相同的示例代码对他来说没有问题。
标签: firefox selenium-webdriver