chromedriver azuredops管道故障

问题描述

我正在尝试在azure管道中运行硒测试,该测试在我的本地计算机上可以通过以下方式正常运行:

options = webdriver.ChromeOptions()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
chrome_exe= ChromeDriverManager()
driver = webdriver.Chrome(executable_path=chrome_exe.install(),options=options)

但是当我在管道中运行相同命令时,它失败并显示以下错误。

E       selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
E         (unknown error: DevToolsActivePort file doesn't exist)
E         (The process started from chrome location /usr/bin/google-chrome is no longer running,so ChromeDriver is assuming that Chrome has crashed.)
/opt/hostedtoolcache/Python/3.6.11/x64/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py:242: WebDriverException
---------------------------- Captured stdout setup -----------------------------
 
---------------------------- Captured stderr setup -----------------------------
[WDM] - Current google-chrome version is 84.0.4147
[WDM] - Get LATEST driver version for 84.0.4147
[WDM] - There is no [linux64] chromedriver for browser 84.0.4147 in cache
[WDM] - Get LATEST driver version for 84.0.4147
[WDM] - Trying to download new driver from http://chromedriver.storage.googleapis.com/84.0.4147.30/chromedriver_linux64.zip
[WDM] - Driver has been saved in cache [/home/vsts/.wdm/drivers/chromedriver/linux64/84.0.4147.30]

我手动转到该路径,它说:没有这样的对象:chromedriver / 84.0.4147.30 但是如果我使用link进行查询 它给出了相同的版本号

解决方法

chromedriver azuredops管道故障

根据错误消息,似乎Chrome浏览器未安装在系统的默认位置。

对于Linux系统,ChromeDriver希望/usr/bin/google-chrome是实际Chrome二进制文件的符号链接。

如果您在非标准位置使用Chrome可执行文件,则可以尝试覆盖Chrome二进制位置,如下所示:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location = "C:\\path\\to\\chrome.exe"    #chrome binary location specified here
options.add_argument("--start-maximized") #open Browser in maximized mode
options.add_argument("--no-sandbox") #bypass OS security model
options.add_argument("--disable-dev-shm-usage") #overcome limited resource problems
options.add_experimental_option("excludeSwitches",["enable-automation"])
options.add_experimental_option('useAutomationExtension',False)
driver = webdriver.Chrome(options=options,executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://google.com/')

您可以检查this thread以获得一些详细信息。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...