【问题标题】:Selenium WebDriverException: Session [null] not available and is not among the last 1000 terminated sessionsSelenium WebDriverException:会话 [null] 不可用并且不在最后 1000 个终止会话中
【发布时间】:2019-08-13 19:48:11
【问题描述】:

我在尝试使用本地运行的 Selenium Grid 导航到 URL(只是简单到 Google)时遇到以下 WebDriver 异常。

org.openqa.selenium.WebDriverException:会话 [null] 不可用 并且不在最后 1000 个终止会话中。

我在我的桌面上运行selenium-server-standalone-3.141.59.jar,采用一个集线器和一个节点的网格配置。在两个不同的 cmd 窗口中,我使用 -role hub 启动集线器,然后使用 -role node -hub http://localhost:4444/grid/register 启动节点。一切似乎都开始了。

Java 代码:

public void initialGridTest() throws Exception {
    try {
        System.setProperty("webdriver.chrome.driver", "D:\\SeleniumWebDrivers\\chromedriver.exe");
        DesiredCapabilities capability = DesiredCapabilities.chrome();
        RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);

        driver.get("http://www.google.com");
        String doodleText = driver.findElement(By.id("logo-doodle-image")).getText();
    } catch (Exception e) {
        System.out.println("e: " + e);
    }
}

我在 IntelliJ 中运行的 Java 类中有一个简单的测试,它调用 RemoteWebDriver 来导航到 Google。当我在代码中执行new RemoteWebDriver(... 时,我看到我的Java 程序连接到集线器并且集线器与节点连接,并且节点打开了一个新的Chrome 实例。但是当程序运行driver.get() 我得到WebDriverException。我在节点控制台中看到它有一个会话 ID,但由于某种原因,我的 Java 代码中的会话为空。

【问题讨论】:

  • 已解决!结果是我为我的网格集线器和节点运行 selenium-server-standalone-3.141.59.jar,但我在 IntelliJ 中的 Java 代码的 pom.xml 正在拉取 Selenium 版本 2.53.0。只是强调了保持所有不同 Selenium 部分(服务器 jar、Java 代码、浏览器驱动程序等)的所有单独版本同步的重要性!是否有电子表格可以定义所有这些?

标签: selenium selenium-webdriver webdriver selenium-grid


【解决方案1】:

此错误消息...

org.openqa.selenium.WebDriverException: Session [null] not available and is not among the last 1000 terminated sessions.

...暗示 Selenium Grid Node 无法与 Selenium Grid Hub 通信。

根据以下讨论:

这个错误似乎源于以下情况:

  • Selenium Grid HubSelenium Grid Node客户端进程不同版本 启动/生成Selenium 客户端。

解决方案

确保Selenium Grid HubSelenium Grid Node客户端进程都使用相同版本的Selenium 客户端,即 Selenium v​​3.141.59

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-11
    • 1970-01-01
    • 1970-01-01
    • 2023-03-04
    • 2012-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多