我试图用一个URL启动chrome浏览器,浏览器启动后,它什么也不做。

1分钟后我看到如下错误:

Unable to open browser with url: 'https://www.google.com' (Root cause: org.openqa.selenium.WebDriverException: unknown error: DevToolsActivePort file doesn't exist
  (Driver info: chromedriver=2.39.562718 (9a2698cba08cf5a471a29d30c8b3e12becabb0e9),platform=Windows NT 10.0.15063 x86_64) (WARNING: The server did not provide any stacktrace information)

我的配置:

Chrome浏览器:66 ChromeBrowser: 2.39.56

又及,在Firefox中一切都很好


当前回答

更新conf.js中的功能

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['todo-spec.js'],
  capabilities: {
    browserName: 'chrome',
    chromeOptions: {
      args: ['--disable-gpu', '--no-sandbox', '--disable-extensions', '--disable-dev-shm-usage']
    }
  },

};

其他回答

我在Docker容器中通过Behat/Mink和Selenium运行Chrome时也遇到了同样的问题。经过一番折腾,我得出了如下结论。Yml提供上面提到的开关。请注意,要使它成功运行,所有这些都是必需的。

default:
    extensions:
        Behat\MinkExtension:
            base_url: https://my.app/
            default_session: selenium2
            selenium2:
                browser: chrome
                capabilities:
                    extra_capabilities:
                        chromeOptions:
                            args:
                                - "headless"
                                - "no-sandbox"
                                - "disable-dev-shm-usage"

没有解决方法对我有效。但这里有一个变通办法:

maxcounter=5
for counter in range(maxcounter):
    try:           
        driver = webdriver.Chrome(chrome_options=options,
                          service_log_path=logfile,
                          service_args=["--verbose", "--log-path=%s" % logfile])
        break
    except WebDriverException as e:
        print("RETRYING INITIALIZATION OF WEBDRIVER! Error: %s" % str(e))
        time.sleep(10)
        if counter==maxcounter-1:
            raise WebDriverException("Maximum number of selenium-firefox-webdriver-retries exceeded.")

更新:

我能够通过这个问题,现在我能够访问chrome所需的url。

对所提供解决方案的尝试结果:

我尝试了上面提供的所有设置,但我无法解决这个问题

关于问题的解释:

根据我的观察,DevToolsActivePort文件不存在的原因是chrome无法在scoped_dirXXXXX文件夹中找到它的引用。

为解决该问题所采取的步骤

我已经杀死了所有的chrome进程和chrome驱动程序进程。 添加下面的代码来调用chrome System.setProperty(“webdriver.chrome.driver”、“pathto \ \ chromedriver.exe”); ChromeOptions选项=新的ChromeOptions(); 选项。setExperimentalOption(“useAutomationExtension”,假); WebDriver驱动=新的ChromeDriver(选项); driver.get (url);

使用上述步骤,我能够解决这个问题。

谢谢你的回答。

I started seeing this problem on Monday 2018-06-04. Our tests run each weekday. It appears that the only thing that changed was the google-chrome version (which had been updated to current) JVM and Selenium were recent versions on Linux box ( Java 1.8.0_151, selenium 3.12.0, google-chrome 67.0.3396.62, and xvfb-run). Specifically adding the arguments "--no-sandbox" and "--disable-dev-shm-usage" stopped the error. I'll look into these issues to find more info about the effect, and other questions as in what triggered google-chrome to update.

ChromeOptions options = new ChromeOptions();
        ...
        options.addArguments("--no-sandbox");
        options.addArguments("--disable-dev-shm-usage");

我的端口号错了。检查启动Selenium服务器时的端口号是否与脚本中的端口号相同。