WebDriverException (Status code 127) when running Selenium + webdriver_manager on gitlab-CI machine (linux)

1.3k views Asked by At

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

1

There are 1 answers

3
undetected Selenium On

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.