尝试使用本地运行的 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 通信。
根据以下讨论:
- Session [url] not available and is not among the last 1000 terminated sessions. How to solve this?
- Selenium: Session externalKey not available
似乎这个错误源于:
- Selenium Grid Hub、Selenium Grid Node 和Client Process 是从不同版本 Selenium 客户端。
解决方案
确保Selenium Grid Hub、Selenium Grid Node 和Client Process 都使用相同版本的Selenium 客户端即 Selenium v3.141.59
关于 Selenium WebDriverException : Session [null] not available and is not among the last 1000 terminated sessions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57484429/