当前位置: 首页 > 知识库问答 >
问题:

UnreachableBrowserException:无法启动新会话。可能的原因是ChromeDriver的远程服务器地址无效

龙玄天
2023-03-14

密码

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import java.io.File;
import java.util.HashMap;

public class tttt {
    public static void main(String[] args) throws InterruptedException {
        ChromeOptions options = new ChromeOptions();
        HashMap<String, Object> chromePrefs = new HashMap<>();
        //mePrefs.put("download.default_directory", new File(RobotPay.class.getClassLoader().getResource("alipaycaptchatmp/").getFile()).getAbsolutePath());
        chromePrefs.put("download.prompt_for_download", false);
        chromePrefs.put("download.directory_upgrade", true);
        chromePrefs.put("safebrowsing.enabled",true);
        chromePrefs.put("profile.managed_default_content_settings.images", 2);//禁图片
        options.setExperimentalOption("prefs", chromePrefs);
        options.addArguments("--headless");
        options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
        options.addArguments("--no-sandbox"); // Bypass OS security model

        System.setProperty("webdriver.chrome.driver", args[0]);
        options.setBinary(args[1]);


        ChromeDriver dr = new ChromeDriver(options);


    }
}

错误:

[qateadmin@UAT13352 ~]$ java -cp "/opt/tars/apps/100018485/releases/762245/WEB-INF/lib/*:./" tttt /opt/tars/apps/100018485/releases/762245/WEB-INF/classes/seleniumdriver/chromedriver /usr/bin/google-chrome
Starting ChromeDriver 2.45.615279 (12b89733300bd268cff3b78fc76cb8f3a7cc44e5) on port 4461
Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'UAT13352', ip: '10.5.117.188', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-327.4.5.el7.x86_64', java.version: '1.7.0_51'
Driver info: driver.version: ChromeDriver
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:170)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:159)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:148)
        at tttt.main(tttt.java:25)
Caused by: java.lang.IllegalStateException: The process has not exited yet therefore no result is available ...
        at org.apache.commons.exec.DefaultExecuteResultHandler.getException(DefaultExecuteResultHandler.java:76)
        at org.openqa.selenium.os.UnixProcess.checkForError(UnixProcess.java:171)
        at org.openqa.selenium.os.CommandLine.checkForError(CommandLine.java:185)
        at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:177)
        at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:166)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
        ... 7 more

Chrome版本:

[qateadmin@UAT13352 ~]$ google-chrome -version
Google Chrome 71.0.3578.98

chrome可执行模式为777

chromedriver版本:2.45(支持ChromeV70-72,模式为777

操作系统:centos_x64

此外,我在本地Ubuntu16.04_x64和CentOS7_x6虚拟机上测试了它,没有例外。我被这个问题难住了,有什么建议吗?

更新
将java升级到java SE 8u191后,错误消息如下:

[qateadmin@UAT13352 ~]$ java -cp "/opt/tars/apps/100018485/releases/762245/WEB-INF/lib/*:./" tttt /opt/tars/apps/100018485/releases/762245/WEB-INF/classes/seleniumdriver/chromedriver /usr/bin/google-chrome
Starting ChromeDriver 2.45.615279 (12b89733300bd268cff3b78fc76cb8f3a7cc44e5) on port 3602
Only local connections are allowed.
Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'UAT13352', ip: '10.5.117.188', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-327.4.5.el7.x86_64', java.version: '1.8.0_191'
Driver info: driver.version: ChromeDriver
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:665)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:144)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:170)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:159)
        at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:148)
        at tttt.main(tttt.java:25)
Caused by: java.lang.IllegalStateException: The process has not exited yet therefore no result is available ...
        at org.apache.commons.exec.DefaultExecuteResultHandler.getException(DefaultExecuteResultHandler.java:76)
        at org.openqa.selenium.os.UnixProcess.checkForError(UnixProcess.java:171)
        at org.openqa.selenium.os.CommandLine.checkForError(CommandLine.java:185)
        at org.openqa.selenium.remote.service.DriverService.waitUntilAvailable(DriverService.java:177)
        at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:166)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:78)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
        ... 7 more

共有1个答案

胡劲
2023-03-14

此错误消息...

Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '2.53.1', revision: 'a36b8b1cd5757287168e54b817830adce9b0158d', time: '2016-06-30 19:26:09'
System info: host: 'UAT13352', ip: '10.5.117.188', os.name: 'Linux', os.arch: 'amd64', os.version: '3.10.0-327.4.5.el7.x86_64', java.version: '1.7.0_51'
.
Caused by: java.lang.IllegalStateException: The process has not exited yet therefore no result is available ...

…意味着ChromeDriver无法启动/生成新的Web浏览器,即Chrome浏览器会话。

您的主要问题是您使用的二进制文件版本之间的不兼容性,如下所示:

    < li >您的JDK版本是1.7.0_51,这相当古老。 < li >您的Selenium客户端版本是2016-06-30 19:26:09的2.53.1,比这个版本早了近3年。

所以JDK v7u51、Selenium客户端v2.53.1、ChromeDriver v2.45和谷歌Chrome 71.0.3578.98之间存在明显的不匹配。

  • 将 JDK 升级到最新级别 JDK 8u191。
  • 将硒升级到当前级别版本3.141.59。
  • 将浏览器驱动程序升级到当前的浏览器驱动程序 v2.45 级别。
  • 将浏览器版本保持在浏览器v670-72级别之间。(根据浏览器驱动程序 v2.42 发行说明)
  • 通过 IDE 清理项目工作区,并仅使用所需的依赖项重新生成项目。
  • 如果您的基本 Web 客户端版本太旧,请通过 Revo 卸载程序将其卸载,并安装 Web 客户端的最新 GA 和已发布版本。
  • 重新启动系统。
  • 执行您的@Test
 类似资料: