WebDriverexception(状态代码127)运行硒+ gitlab-ci机器上的webdriver_manager(Linux)

发布于 2025-01-22 05:28:32 字数 1865 浏览 0 评论 0原文

我在GitLab上运行了一条简单的CI管道,用于无头selenium脚本 +使用webdriver_manager来处理Chrome驱动程序二进制。

该部分通过:

Get LATEST chromedriver version for None google-chrome
There is no [linux64] chromedriver for browser None in cache
Trying to download new driver from https://chromedriver.storage.googleapis.com/100.0.4896.60/chromedriver_linux64.zip
Driver has been saved in cache [/root/.wdm/drivers/chromedriver/linux64/100.0.4896.60]

但是在那之后,我会遇到此错误:

WebDriverException: Message: Service /root/.wdm/drivers/chromedriver/linux64/100.0.4896.60/chromedriver unexpectedly exited. Status code was: 127`

问题是什么?似乎WebDriver_Manager在CI中运行有问题。

这是一个简单的复制脚本:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
service = Service(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=chrome_options)

driver.get("http://google.com")
driver.find_element('name', 'q').send_keys("Wikipedia")


这是管道之一: htttps://gitlab.com/mmonfared/mmonfared/test/test/-/jobs/jobs/jobs/jobs/jobs/23506977126

这是一个示例项目: https://gitlab.com/mmonfared/test/test

我也在webriver_manager github github repo中开了一个问题, no answers yet:

https://github.com/SergeyPirogov/webdriver_manager/issues/363

I'm running a simple CI pipeline on GitLab for a Selenium script headlessly + using webdriver_manager to handle chrome driver binary.

This part is passed:

Get LATEST chromedriver version for None google-chrome
There is no [linux64] chromedriver for browser None in cache
Trying to download new driver from https://chromedriver.storage.googleapis.com/100.0.4896.60/chromedriver_linux64.zip
Driver has been saved in cache [/root/.wdm/drivers/chromedriver/linux64/100.0.4896.60]

But after that I'm getting this error:

WebDriverException: Message: Service /root/.wdm/drivers/chromedriver/linux64/100.0.4896.60/chromedriver unexpectedly exited. Status code was: 127`

What is the problem? Seems like webdriver_manager has a problem by running in CI.

Here is a simple script for reproduce:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
service = Service(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=chrome_options)

driver.get("http://google.com")
driver.find_element('name', 'q').send_keys("Wikipedia")


This is one of the pipelines:
https://gitlab.com/mmonfared/test/-/jobs/2350697126

This is a sample project:
https://gitlab.com/mmonfared/test

I've also opened an issue in webdriver_manager github repo, no answers yet:

https://github.com/SergeyPirogov/webdriver_manager/issues/363

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水染的天色ゝ 2025-01-29 05:28:32

此错误消息...

WebDriverException: Message: Service /root/.wdm/drivers/chromedriver/linux64/100.0.4896.60/chromedriver unexpectedly exited. Status code was: 127`

...意味着您正在执行测试作为 root 用户。


深度潜水

不会立即启动或崩溃

在启动期间,Chrome崩溃的常见原因是运行Chrome
Linux上的root用户(管理员)。虽然有可能工作
通过传递- no-sandbox flag在创建您的问题时
WebDriver会话,这种配置不受支持,并且高度
灰心。请配置您的环境以将Chrome运行为
代替常规用户。


解决方案

将测试执行为 non-root 用户。

This error message...

WebDriverException: Message: Service /root/.wdm/drivers/chromedriver/linux64/100.0.4896.60/chromedriver unexpectedly exited. Status code was: 127`

...implies that you are executing your tests as the root user.


Deep Dive

As per Chrome doesn't start or crashes immediately

A common cause for Chrome to crash during startup is running Chrome as
root user (administrator) on Linux. While it is possible to work
around this issue by passing --no-sandbox flag when creating your
WebDriver session, such a configuration is unsupported and highly
discouraged. Please configure your environment to run Chrome as a
regular user instead.


Solution

Execute your tests as a non-root user.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文