Selenium WebDriverException : Session [null] not available and is not among the last 1000 terminated sessions

标签 selenium selenium-webdriver webdriver selenium-grid

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

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

我在桌面上运行 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。我在节点控制台中看到它有一个 session ID,但由于某种原因, session 在我的 Java 中为空代码。

最佳答案

这个错误信息...

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 NodeClient Process 是从不同版本 Selenium 客户端。

解决方案

确保Selenium Grid HubSelenium Grid NodeClient Process 都使用相同版本的Selenium 客户端即 Selenium v​​3.141.59

关于 Selenium WebDriverException : Session [null] not available and is not among the last 1000 terminated sessions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57484429/

相关文章:

java - 如何处理页面未找到或显示异常

python - 无法单击并按住 Selenium 中的元素

android - android appium 不支持滑动方法

python - 在 Pytest 中,根级别的 conftest.py 是否会被树中更深处的 conftest 覆盖?

java - xpath 内部如何工作?

python - WebDriverWait 预期条件中的逻辑运算符

java - 从属性文件设置 SuiteClassess 并在命令行中 indtentify 属性文件

javascript - Selenium: "is not clickable at point"如何等待所有脚本加载完毕

java - 如何通过 Selenium 根据 HTML 提取跨度内的文本 209.520?

java - 在 Eclipse 中运行第一个 Selenium 测试后出现错误