开发者问题收集

Robot 框架 WebDriverException:消息:未知错误:Chrome 无法启动:

2019-03-11
11117

当我使用 robot 框架运行 chrome 浏览器打开测试用例时,我观察到以下错误。

WebDriverException: 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=72.0.3626.69 (3c16f8a135abc0d4da2dff33804db79b849a7c38),platform=Linux 4.4.0-31-generic x86_64)

粘贴以下 robot 脚本:

*** settings ***

Library  Selenium2Library


*** Variables ***

${Browser}  Chrome
${URL}  https://www.google.com

*** Test Cases ***
TC001 Browser Start and Close
    Open Browser  ${URL}  ${Browser}

使用的 chrome 版本:

  • Chrome 版本 72
  • ChromeDriver 72.0.3626.69
3个回答

我解决了!使用 --no-sandbox

${chrome_options}=  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys, selenium.webdriver
Call Method    ${chrome_options}    add_argument    test-type
Call Method    ${chrome_options}    add_argument    --disable-extensions
Call Method    ${chrome_options}    add_argument    --headless
Call Method    ${chrome_options}    add_argument    --disable-gpu
Call Method    ${chrome_options}    add_argument    --no-sandbox
Create Webdriver    Chrome    chrome_options=${chrome_options}

而不是

Open Browser    about:blank    headlesschrome
Open Browser    about:blank    chrome
Panup Pong
2019-09-19

这是一种对我有用的方法。我们必须在打开浏览器时传递 chrome_options 和 chrome web 驱动程序路径。请查看下面的代码。

*** Settings ***
Library           Selenium2Library

*** Variables ***
${URL}            https://www.google.com
${CHROMEDRIVER_PATH}        /usr/local/bin/chromedriver

*** Keywords ***
Open Website
    ${chrome_options}=  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys, selenium.webdriver
    Call Method    ${chrome_options}    add_argument    --no-sandbox
    Call Method    ${chrome_options}    add_argument    --headless
    Open Browser    ${URl}    chrome    options=${chrome_options}      executable_path=${CHROMEDRIVER_PATH}

*** Settings ***
Suite Setup       Open Website

注意: chrome_options executable_path 已直接传递给 Open Browser 命令,而不是创建 web 驱动程序(因为出于某种原因,创建 web 驱动程序对我来说不起作用。但将参数直接传递给浏览器却有效)

Dhivya Dandapani
2020-10-15

您还需要更新 Selenium,如果您使用最新版本的 SeleniumLibrary(它已从名称中删除“2”),您将获得此更新。

使用新名称更新您的脚本并使用以下内容进行更新:

pip install -U robotframework-seleniumlibrary
Helio
2019-03-11