WebDriver异常:InitSession错误未知错误:Chrome无法启动:崩溃

时间:2020-07-16 03:34:16

标签: selenium-chromedriver

我在Mac上本地运行Selenium,但不断收到错误消息:

Starting ChromeDriver 84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310}) on port 38869
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.WebDriverException: unknown error: Chrome failed to start: crashed.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /Users/wngo/buzzho/src/main/resources/Chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'C02Z50V8LVDT.grubhub.local', ip: 'fe80:0:0:0:1020:d809:2ed6:d90b%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.14.6', java.version: '1.8.0_231'
Driver info: driver.version: ChromeDriver
remote stacktrace: 0   chromedriver_mac                    0x000000010aa75c49 chromedriver_mac + 4893769
1   chromedriver_mac                    0x000000010aa0f0e3 chromedriver_mac + 4473059
2   chromedriver_mac                    0x000000010a6828fd chromedriver_mac + 751869
3   chromedriver_mac                    0x000000010a5e0fa4 chromedriver_mac + 90020
4   chromedriver_mac                    0x000000010a5dd9b9 chromedriver_mac + 76217
5   chromedriver_mac                    0x000000010a610043 chromedriver_mac + 282691
6   chromedriver_mac                    0x000000010a60ce43 chromedriver_mac + 269891
7   chromedriver_mac                    0x000000010a5e662a chromedriver_mac + 112170
8   chromedriver_mac                    0x000000010a5e7635 chromedriver_mac + 116277
9   chromedriver_mac                    0x000000010aa375af chromedriver_mac + 4638127
10  chromedriver_mac                    0x000000010aa4491b chromedriver_mac + 4692251
11  chromedriver_mac                    0x000000010aa446bb chromedriver_mac + 4691643
12  chromedriver_mac                    0x000000010aa1b109 chromedriver_mac + 4522249
13  chromedriver_mac                    0x000000010aa44ea3 chromedriver_mac + 4693667
14  chromedriver_mac                    0x000000010aa2d073 chromedriver_mac + 4595827
15  chromedriver_mac                    0x000000010aa5c094 chromedriver_mac + 4788372
16  chromedriver_mac                    0x000000010aa7bdb7 chromedriver_mac + 4918711
17  libsystem_pthread.dylib             0x00007fff774e82eb _pthread_body + 126
18  libsystem_pthread.dylib             0x00007fff774eb249 _pthread_start + 66
19  libsystem_pthread.dylib             0x00007fff774e740d thread_start + 13

这是chromedriver.log的内容:

[1594869395.109][INFO]: Launching chrome: /Users/wngo/buzzho/src/main/resources/Chromium --data-path=/tmp/data-path --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-gpu --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --disk-cache-dir=/tmp/cache-dir --enable-automation --enable-blink-features=ShadowDOMV0 --enable-logging --headless --homedir=/tmp --log-level=3 --no-first-run --no-sandbox --password-store=basic --remote-debugging-port=0 --single-process --start-maximized --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/user-data --window-size=1024x768
[1594869395.168][INFO]: [1beaee5b7391d5f4e1cd3129cb447869] RESPONSE InitSession ERROR unknown error: Chrome failed to start: crashed.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /Users/wngo/buzzho/src/main/resources/Chromium is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
[1594869395.168][DEBUG]: Log type 'driver' lost 0 entries on destruction
[1594869395.168][DEBUG]: Log type 'browser' lost 0 entries on destruction

这是我的环境:

OS: MacOS Mojave
ChromeDriver: 84.0.4147.30
Chromium: latest

这就是我启动WebDriver的方式:

    public static WebDriver getHeadlessDriver() {

        System.setProperty("webdriver.chrome.logfile", "../chromedriver.log");
        System.setProperty("webdriver.chrome.verboseLogging", "true");

        System.setProperty("webdriver.chrome.driver", "../chromedriver_mac");

        ChromeOptions chromeOptions = new ChromeOptions();

        chromeOptions.addArguments("--headless");
        chromeOptions.addArguments("--no-sandbox");
        chromeOptions.addArguments("--disable-dev-shm-usage");
        chromeOptions.addArguments("--disable-gpu");
        chromeOptions.addArguments("--window-size=1024x768");
        chromeOptions.addArguments("--user-data-dir=/tmp/user-data");
        chromeOptions.addArguments("--enable-logging");
        chromeOptions.addArguments("--single-process");
        chromeOptions.addArguments("--data-path=/tmp/data-path");
        chromeOptions.addArguments("--homedir=/tmp");
        chromeOptions.addArguments("--disk-cache-dir=/tmp/cache-dir");
        chromeOptions.addArguments("--log-level=3");
        chromeOptions.addArguments("start-maximized");
        chromeOptions.addArguments("--disable-extensions");
        chromeOptions.setExperimentalOption("useAutomationExtension", false);
        chromeOptions.setBinary("../Chromium");

        return new ChromeDriver(chromeOptions);
    }

如果有人可以帮助我,我非常感谢。我一直在努力解决这个问题。谢谢。

0 个答案:

没有答案