Chrome 'org.openqa.selenium.WebDriverException:未知错误:由于页面崩溃而删除会话'

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

我有一个独立的Chrome Docker镜像,我想在Java 17中使用它。我的Docker文件是:

FROM selenium/standalone-chrome:115.0

RUN wget -O- https://apt.corretto.aws/corretto.key | sudo apt-key add -

RUN sudo apt update
# RUN sudo apt upgrade
RUN sudo apt-get -y install software-properties-common
RUN sudo add-apt-repository 'deb https://apt.corretto.aws stable main'
RUN sudo apt-get update
RUN sudo apt-get install -y java-17-amazon-corretto-jdk

ENV CHROMEDRIVER_PORT 4444
ENV CHROMEDRIVER_WHITELISTED_IPS "127.0.0.1"
ENV CHROMEDRIVER_URL_BASE ''
EXPOSE 4444

EXPOSE 8080
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
# For Testing
ENTRYPOINT ["java","-jar", "-Xmx600m","/app.jar"]

我的java代码是

//            System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");

            ChromeOptions chromeOptions = new ChromeOptions();
//            chromeOptions.setBinary("/usr/local/bin/chrome");
            chromeOptions.addArguments("--headless=new");
            chromeOptions.addArguments("--no-sandbox");
            chromeOptions.addArguments("--disable-gpu");
            chromeOptions.addArguments("--remote-allow-origins=*");
    WebDriver webDriver = new ChromeDriver(chromeOptions);
    webDriver.get("https://www.google.com/");

我看到两个错误:

The chromedriver version (115.0.5790.102) detected in PATH at /usr/bin/chromedriver might not be compatible with the detected chrome version (115.0.5790.110); currently, chromedriver 115.0.5790.170 is recommended for chrome 115.*, so it is advised to delete the driver in PATH and retry

并且还

org.openqa.selenium.WebDriverException: unknown error: session deleted because of page crash
from tab crashed
  (Session info: chrome=115.0.5790.110)
Build info: version: '4.11.0', revision: '040bc5406b'
System info: os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.49-linuxkit', java.version: '17.0.8.1'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Command: [29d1fa15d0fab05c1c479470b82aaa69, get {url=https://www.kcrg.com/2022/02/08/john-deere-acquires-majority-ownership-battery-manufacturer/}]
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 115.0.5790.110, chrome: {chromedriverVersion: 115.0.5790.102 (90efd4b0ad6..., userDataDir: /tmp/.org.chromium.Chromium...}, goog:chromeOptions: {debuggerAddress: localhost:43301}, networkConnectionEnabled: false, pageLoadStrategy: normal, platformName: linux, proxy: Proxy(), se:cdp: ws://localhost:43301/devtoo..., se:cdpVersion: 115.0.5790.110, setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:credBlob: true, webauthn:extension:largeBlob: true, webauthn:extension:minPinLength: true, webauthn:extension:prf: true, webauthn:virtualAuthenticators: true}

有人知道如何诊断/修复吗?

uqxowvwt

uqxowvwt1#

答案是,我需要将arguments.add("--disable-dev-shm-usage");添加到选项中。现在起作用了

相关问题