我想使用硒和铬浏览器运行测试,但出现此错误
Message: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 4.4.0-31-generic x86_64)
在堆栈溢出的许多答案中,建议使用无头镀铬。我使用了它,它在无头模式下工作得很好,但是问题是我不想在无头模式下运行测试吗?
这是我的浏览器选项
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("start-maximized")
chrome_options.add_argument("disable-infobars")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-gpu")
我希望在非无头模式下运行测试。
答案 0 :(得分:-1)
此错误消息...
Message: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 4.4.0-31-generic x86_64)
...表示 ChromeDriver 无法启动/产生新的 WebBrowser ,即 Chrome浏览器会话。
您的主要问题是通过Options
类的实例,即 chrome_options ,在 WebDriver 配置中的不兼容性 >
从日志中可以清楚地看到您正在使用基于 Linux 的系统:
platform=Linux 4.4.0-31-generic x86_64
在 Linux系统和 MacOS 上不需要根据Headless: make --disable-gpu flag unnecessary --disable-gpu
标志。您可以在How to configure ChromeDriver to initiate Chrome browser in Headless mode through Selenium?
最后,根据最佳实践,您需要确保:
Test
。driver.quit()
方法内调用tearDown(){}
,以优雅地关闭和销毁 WebDriver 和 Web Client 实例。