“org.openqa.selenium.WebDriverException:未知错误:会话因页面崩溃而删除”

'org.openqa.selenium.WebDriverException: unknown error: session deleted because of page crash'

提问人:HeronAlgoSearch 提问时间:8/23/2023 更新时间:8/24/2023 访问量:119

问:

我有独立的 chrome Docker 映像,我想将它与 Java17 一起使用。我的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}

有谁知道如何诊断/修复?

java google-chrome selenium-chromedriver

评论


答:

0赞 HeronAlgoSearch 8/24/2023 #1

答案是我需要添加到选项中。它现在可以工作了。arguments.add("--disable-dev-shm-usage");