开发者问题收集

selenium.WebDriverException:未知错误:由于选项卡崩溃导致页面崩溃,会话被删除

2020-03-13
12129

注意:我的问题之前已经关闭了,我尝试了这里提到的解决方案 - 未知错误:由于页面崩溃导致会话被删除,未知错误:无法确定因 ChromeDriver Selenium 崩溃的选项卡的加载状态 - 添加了这些选项 - options.addArguments("--disable-dev-shm-usage"); options.addArguments("--no-sandbox"); -- 我仍然看到问题

在 selenium 网格中运行时,在某些情况下单个测试出现以下错误:

Hooks 方法 1:

org.openqa.selenium.WebDriverException: unknown error: session deleted because of page crash
from tab crashed
  (Session info: chrome=80.0.3987.106)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-37JVVAA', ip: '169.254.210.134', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 80.0.3987.106, chrome: {chromedriverVersion: 80.0.3987.106 (f68069574609..., userDataDir: /tmp/.com.google.Chrome.TQ7Z9v}, goog:chromeOptions: {debuggerAddress: localhost:41695}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: none, platform: LINUX, platformName: LINUX, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webdriver.remote.sessionid: 2ac66b1a001b0b8c6c24da9821b...}
Session ID: 2ac66b1a001b0b8c6c24da9821b8f1e2

Hooksmethod2:

org.openqa.selenium.NoSuchSessionException: invalid session id
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-37JVVAA', ip: '169.254.210.134', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 80.0.3987.106, chrome: {chromedriverVersion: 80.0.3987.106 (f68069574609..., userDataDir: /tmp/.com.google.Chrome.TQ7Z9v}, goog:chromeOptions: {debuggerAddress: localhost:41695}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: none, platform: LINUX, platformName: LINUX, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webdriver.remote.sessionid: 2ac66b1a001b0b8c6c24da9821b...}
Session ID: 2ac66b1a001b0b8c6c24da9821b8f1e2

Hooksmethod3:

org.openqa.selenium.WebDriverException: Session [2ac66b1a001b0b8c6c24da9821b8f1e2] was terminated due to BROWSER_TIMEOUT
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-37JVVAA', ip: '169.254.210.134', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 80.0.3987.106, chrome: {chromedriverVersion: 80.0.3987.106 (f68069574609..., userDataDir: /tmp/.com.google.Chrome.TQ7Z9v}, goog:chromeOptions: {debuggerAddress: localhost:41695}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: none, platform: LINUX, platformName: LINUX, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webdriver.remote.sessionid: 2ac66b1a001b0b8c6c24da9821b...}
Session ID: 2ac66b1a001b0b8c6c24da9821b8f1e2

我们在钩子中有 3 个连续的方法 - 看起来第一个问题是根本原因,但我不确定。

以下是用于驱动程序的选项:

            ChromeOptions options = new ChromeOptions();
            options.addArguments("start-maximized");
            options.addArguments("--disable-infobars");
            options.addArguments("--disable-extensions");
            options.addArguments("chrome.switches", "--disable-extensions");
            options.addArguments("--disable-gpu");
            options.addArguments("--disable-dev-shm-usage");
            options.addArguments("--no-sandbox");
            options.addArguments("--disable-notifications");
            options.addArguments("--disable-popup-blocking");
            options.addArguments("enable-automation");
            options.addArguments("--disable-dev-shm-usage");
            options.addArguments("--disable-browser-side-navigation");
            options.addArguments("--dns-prefetch-disable");
            options.setPageLoadStrategy(PageLoadStrategy.NONE);
            options.setExperimentalOption("useAutomationExtension", false);
            driver = new RemoteWebDriver(new URL(AWS_URL), options);

以下是我们在 kubernetest yaml 文件中使用的覆盖:

  chrome:
    ## Enable the creation of a node-chrome pod
    enabled: true
    replicas: 65
    javaOpts: "-Xmx1024m -XX:+UseSerialGC"
    resources:
      limits:
        cpu: ".5"
        memory: "1000Mi"
    env:
      sessionTimeout: 60
  hub:
    env:
      sessionTimeout: 60
    ##gridBrowserTimeout
    gridBrowserTimeout: 240
    livenessTimeout: 15
    readinessTimeout: 15
    gridJettyMaxThreads: 1024
    gridTimeout: 60
    gridCleanUpCycle: 5000
    gridNewSessionWaitTimeout: -1
    javaOpts: "-Xmx1024m -XX:+UseSerialGC"

    ## ref: http://kubernetes.io/docs/user-guide/compute-resources/
    resources:
      limits:
        cpu: "3"
        memory: "2048Mi"
 Please help
3个回答

我遇到了同样的问题,通过在 docker-compose.yml 文件中为 chrome 容器添加 -/dev/shm:/dev/shm 解决了这个问题
参考: https://github.com/SeleniumHQ/docker-selenium

chrome:
 image: selenium/node-chrome
 depends_on:
  - selenium-hub
 volumes:
  - /dev/shm:/dev/shm
 environment:
  HUB_PORT_4444_TCP_ADDR: selenium-hub
  HUB_PORT_4444_TCP_PORT: 4444
  NODE_MAX_SESSION: 2
  NODE_MAX_INSTANCES: 2
ThimiraR
2020-07-08

我在 Chrome 和 Firefox 上遇到了同样的问题。我通过增加两个容器的大小 ( shm_size ) 解决了这个问题。

version: "3"
services:
  hub:
    image: selenium/hub
    ports:
      - "4444:4444"
  chrome:
    image: selenium/node-chrome
    shm_size: '1gb'
    depends_on:
      - hub
    environment:
      - HUB_HOST=hub
  firefox:
    image: selenium/node-firefox
    shm_size: '1gb'
    depends_on:
      - hub
    environment:
      - HUB_HOST=hub
Azhar Wahab
2020-08-08

这可能是由 Docker 本身的内存限制引起的。2GB 的限制会重现此问题,而 4GB 的限制不会重现此问题。这可以在 Docker 仪表板 > 设置 > 资源中更改。

Charlie
2024-02-07