Chrome 未创建会话异常错误:无法启动新会话,通过pom.xml使用Selenium Java和WebDriverManager时出现响应代码500错误

enyaitl3  于 2022-12-06  发布在  Go
关注(0)|答案(2)|浏览(264)

我想在chrome测试版上测试我的脚本,为此我安装了chrome测试版,但不知何故,我无法使用Selenium Java启动它。我在pom.xml文件中添加了所有需要的依赖项,这些依赖项涉及webdriver管理器等。我正在共享我的控制台错误和脚本。

ChromeOptions optionsBeta = new ChromeOptions();
optionsBeta.setBinary("C:\\Users\\WRP\\Downloads\\Programs\\ChromeSetup.exe");
System.setProperty("webdriver.chrome.driver", "C:\\Users\\WRP\\eclipse-workspace\\PracticeProject\\Driver\\chromedriver.exe");
WebDriver driver = new ChromeDriver(optionsBeta);
//System.setProperty("webdriver.chrome.driver", "./Driver/chromedriver.exe");
//  WebDriver driver = new ChromeDriver();
WebDriverManager.chromedriver().setup();
//WebDriverManager.chromedriver().driverVersion("104.0.5112.29").setup();
//WebDriver driver = new ChromeDriver();
WebDriverWait waits=new WebDriverWait (driver, Duration.ofSeconds(10));

错误跟踪日志:

Starting ChromeDriver 104.0.5112.29 (eff877e18f767c77fef0481a1cba402c8cbad404-refs/branch-heads/5112@{#422}) on port 55215
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: Chrome failed to start: crashed.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location C:\Users\WRP\Downloads\Programs\ChromeSetup.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '4.3.0', revision: 'a4995e2c09*'
System info: host: 'AWAIS-PC', ip: '192.168.1.62', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '18.0.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [null, newSession {capabilities=[Capabilities {browserName: chrome, goog:chromeOptions: {args: [], binary: C:\Users\WRP\Downloads\Prog..., extensions: []}}], desiredCapabilities=Capabilities {browserName: chrome, goog:chromeOptions: {args: [], binary: C:\Users\WRP\Downloads\Prog..., 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:70)
    at First_Test.Practice_First.main(Practice_First.java:29)
nfeuvbwi

nfeuvbwi1#

此错误消息...

Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Response code 500. Message: unknown error: Chrome failed to start: crashed.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location C:\Users\WRP\Downloads\Programs\ChromeSetup.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

...表示ChromeDriver无法启动/产生新的 * 浏览上下文 *,即google-chrome会话。
您必须注意以下几点:

  • setBinary()参数应用于指向二进制可执行文件,即 * chrome.exe * 浏览器软件安装后(* ChromeSetup.exe *)
optionsBeta.setBinary("C:\\location\\to\\chrome.exe");
  • 您可以使用**以下任一***( 而不是两者 *):
  • 下载的chromedriver. exe版本使用System.setProperty()行,如下所示:
System.setProperty("webdriver.chrome.driver", "C:\\Users\\WRP\\eclipse-workspace\\PracticeProject\\Driver\\chromedriver.exe");
  • pom.xml中的***WebDriverManager***依赖项,并将chromedriver设置为:
WebDriverManager.chromedriver().setup();

您的有效代码块将是:

System.setProperty("webdriver.chrome.driver", "C:\\Users\\WRP\\eclipse-workspace\\PracticeProject\\Driver\\chromedriver.exe");
ChromeOptions optionsBeta = new ChromeOptions();
optionsBeta.setBinary("C:\\location\\to\\chrome.exe");      
WebDriver driver = new ChromeDriver(optionsBeta);
  • pom.xml中使用 * Maven依赖关系 *:
WebDriverManager.chromedriver().driverVersion("104.0.5112.29").setup();
ChromeOptions optionsBeta = new ChromeOptions();
optionsBeta.setBinary("C:\\location\\to\\chrome.exe");      
WebDriver driver = new ChromeDriver(optionsBeta);
uhry853o

uhry853o2#

使用下方镶边选项

options = webdriver.ChromeOptions()
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--ignore-ssl-errors=yes')
options.add_argument('--ignore-certificate-errors')

这一行非常重要,请跳过此错误

options.add_argument('--disable-dev-shm-usage')

相关问题