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

Linux平台初始化Google Chrome遇SessionNotCreatedException错误求助

解决Linux下Selenium初始化Chrome提示"cannot find Chrome binary"的问题

以下是针对该问题的排查和解决步骤:

  • 确认Chrome是否安装及路径
    先通过终端命令查找Chrome的安装位置:

    which google-chrome
    # 若使用Chromium则执行
    which chromium-browser
    

    如果命令无输出,说明Chrome未安装,需先安装对应发行版的Chrome包。

  • 安装Chrome(未安装时)
    根据你的Linux发行版执行对应的安装命令:

    • Debian/Ubuntu系:
      sudo apt update && sudo apt install google-chrome-stable
      
    • RHEL/CentOS/Fedora系:
      sudo dnf install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
      
    • Arch系:
      sudo pacman -S google-chrome
      
  • 在代码中指定Chrome binary路径
    如果Chrome已安装但Selenium仍找不到,需在初始化ChromeDriver时显式指定binary路径(以Java为例):

    ChromeOptions chromeOptions = new ChromeOptions();
    // 替换为which命令查到的实际路径
    chromeOptions.setBinary("/usr/bin/google-chrome");
    WebDriver driver = new ChromeDriver(chromeOptions);
    
  • 匹配ChromeDriver与Chrome版本
    版本不兼容也可能引发类似错误,先查看Chrome版本:

    google-chrome --version
    

    下载对应主版本号的ChromeDriver,再通过代码指定Driver路径:

    System.setProperty("webdriver.chrome.driver", "/path/to/your/chromedriver");
    
  • 检查文件权限
    确保运行程序的用户对Chrome binary有执行权限:

    ls -l /usr/bin/google-chrome
    

    若权限不足,执行:

    sudo chmod +x /usr/bin/google-chrome
    

内容的提问来源于stack exchange,提问作者Henrique José Itzcovici

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 05:28:32