【问题标题】:Selenium "session not found" from FirefoxDriver来自 FirefoxDriver 的 Selenium“未找到会话”
【发布时间】: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


【解决方案1】:

我的设置与您完全相同(Windows / Selenium 2.33 / FF 17.0.6 ),我看到的行为完全相同。我已经尝试了所有可以在网上找到的东西。

然后我在某处读到,看到同样问题的用户正在使用他们公司的 FF 17.0.6 ESR 发行版,当他们下载并安装(连同他们的公司 FF 安装)时,他们下载并安装了 FF 17.0.6 ESR 的新副本(以及指出 FF 驱动程序使用新的 Firefox.exe 二进制文件)它工作。

这就是我尝试的方法,因为我使用的是公司部署的 FF 版本,并且它有效!这是我使用 FF 17.0.6 ESR 的第二次安装的代码

File pathToBinary = new File("C:\\Program Files (x86)\\Mozilla Firefox\\Firefox.exe");
FirefoxBinary ffBinary = new FirefoxBinary(pathToBinary);
FirefoxProfile ffProfile = new FirefoxProfile();
WebDriver ffDriver = new FirefoxDriver(ffBinary, ffProfile);
System.out.println("***Execute testGetTitle()");
ffDriver.get(pdURL);

(new WebDriverWait(ffDriver, 10)).until(new ExpectedCondition<Boolean>() {
     public Boolean apply(WebDriver d) {
     return d.getTitle().equals("Your Title Here")
     }
});

ffDriver.quit();

试一试,看看你的 FF 安装是否有问题。

【讨论】:

  • 是的,这是我公司的FF。我实际上卸载了它,解压缩了 FF 19 的副本,把它放在我的路径中,没有 Selenium 可以完美运行。谢谢!
猜你喜欢
  • 2021-06-11
  • 2021-05-06
  • 2014-11-24
  • 2016-12-31
  • 1970-01-01
  • 2020-10-11
  • 2014-03-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多