You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins运行Selenium任务时出现ChromeDriver路径不存在错误

问题:Azure Docker容器中Jenkins执行Selenium任务报错FileNotFoundError

在Azure服务器的Docker容器中运行Jenkins,执行Selenium任务时抛出如下错误:

[Errno 2] No such file or directory: '/root/.cache/selenium/chromedriver/linux64/120.0.6099.109/chromedriver'

File "/var/jenkins_home/workspace/Historical Volume Job/cronjobs/extractCookies.py", line 34, in extract_cookie
    driver = webdriver.Chrome(chrome_options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
    super().__init__(
  File "/usr/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py", line 53, in __init__
    self.service.start()
  File "/usr/lib/python3.11/site-packages/selenium/webdriver/common/service.py", line 105, in start
    self._start_process(self._path)
  File "/usr/lib/python3.11/site-packages/selenium/webdriver/common/service.py", line 207, in _start_process
    self.process = subprocess.Popen(
                   ^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/subprocess.py", line 1026, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.11/subprocess.py", line 1950, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/root/.cache/selenium/chromedriver/linux64/120.0.6099.109/chromedriver'

已确认该文件确实存在于指定路径,本地运行正常,Jenkins传递给Python subprocess的命令为:['/root/.cache/selenium/chromedriver/linux64/120.0.6099.109/chromedriver', '--port=47841']

解决方法

  • 修复文件权限:Jenkins默认以jenkins用户运行,该用户无权限访问/root/.cache/目录。执行以下命令修改权限:

    chmod -R 755 /root/.cache/selenium/
    chmod +x /root/.cache/selenium/chromedriver/linux64/120.0.6099.109/chromedriver
    

    或者直接将chromedriver复制到/var/jenkins_home/等Jenkins可访问的路径下。

  • 调整Jenkins运行用户:如果允许,可修改Jenkins任务以root用户执行,或调整Jenkins服务的运行用户为root(注意安全风险),避免权限隔离问题。

  • 显式指定chromedriver路径:放弃依赖Selenium自动下载的路径,手动下载对应版本的chromedriver到Jenkins工作目录,代码中显式声明路径:

    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service
    
    service = Service(executable_path='/var/jenkins_home/chromedriver')
    driver = webdriver.Chrome(service=service, options=chrome_options)
    
  • 检查容器内Chrome依赖:chromedriver需要对应版本的Chrome浏览器才能运行,确认Docker容器中已安装Chrome(以Debian/Ubuntu为例):

    apt-get update && apt-get install -y chromium-browser
    
  • 验证版本兼容性:确保chromedriver版本与容器内安装的Chrome版本完全匹配,版本不匹配也会触发类似找不到文件的错误。

内容的提问来源于stack exchange,提问作者Mukul Agarwal

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 02:06:08