无法启动新会话,响应代码500,错误信息:错误信息DevToolsActivePort文件不存在错误使用Selenium ChromeDriver Java

hgqdbh6s  于 2023-09-28  发布在  Go
关注(0)|答案(1)|浏览(288)

我是新的 selenium ,我试图打开一个页面,所以打开,但它不能加载URL。
代码试验:

System.setProperty("webdriver.chrome.driver","C:\\Users\\user\\Desktop\\ecli\\chromedriver.exe")
WebDriver driver= new ChromeDriver();
driver.get("https://rahulshettyacademy.com/");
System.out.println(driver.getTitle());

我尝试重新安装Chrome,添加thread.sleep(5000),添加依赖WebDriverManager.chromedriver().setup();WebDriver driver = new ChromeDriver();
关闭Chrome后,我有这个:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Starting ChromeDriver 103.0.5060.134 (8ec6fce403b3feb0869b0732eda8bd95011d333c-refs/branch-heads/5060@{#1262}) on port 54404
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: DevToolsActivePort file doesn't exist
Build info: version: '4.3.0', revision: 'a4995e2c09*'
System info: host: 'PC', ip: '192.168.56.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.3'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [], extensions: []}}}]
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:144)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:102)
    at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:67)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:156)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.invokeExecute(DriverCommandExecutor.java:167)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:142)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:569)
    at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:264)
    at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:179)
    at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:101)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:81)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:49)
    at PrimerEjercicio.main(PrimerEjercicio.java:29)

工作环境:

  • 操作系统:W10
  • Chrome版本:104.0.5112.102
  • jve1.8.0_101(java版本)
envsm3lx

envsm3lx1#

此错误消息...

org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: DevToolsActivePort file doesn't exist

...意味着ChromeDriver无法启动/产生新的 * 浏览上下文 *,即google-chrome会话。
您的主要问题是您正在使用的二进制文件版本之间的不兼容,如下所示:

  • 您正在使用 Chrome=104.0
  • 但您使用的是 chromedriver=103.0
  • chromedriver=103.0的发行说明中明确提到了以下内容:

支持Chrome版本103
因此,chromedriver=103.0chrome=104.0 之间存在明显的不匹配

解决方案

确保:

相关问题