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

Kubuntu 24.04下RobotFramework启动Chromium后无法交互的问题

Kubuntu 24.04下RobotFramework+SeleniumLibrary驱动Snap安装的Chromium失败问题

问题现象

  • 能成功打开Chromium浏览器,但地址栏始终显示data:,,无法执行任何后续交互操作
  • 关闭浏览器后抛出SessionNotCreatedException错误,核心提示为DevToolsActivePort file doesn't exist、Chrome进程已退出,ChromeDriver判定浏览器崩溃

环境配置步骤

python -m venv autolab
source autolab/bin/activate
pip install robotframework robotframework-seleniumlibrary
  • Chromium通过Ubuntu Snap方式安装

测试用例

测试用例1

*** Settings ***
Documentation     Open Chromium on a given URL.
Library           SeleniumLibrary

*** Test Cases ***
interact with browser
  open browser  https://robotframework.org  Chrome
  location should be  https://robotframework.org

测试用例2

*** Settings ***
Documentation     Use ChromeDriver to open Chromium on a given URL.
Library           SeleniumLibrary

*** Test Cases ***
interact with browser
  create webdriver    Chrome
  go to    http://robotframework.org
  location should be  https://robotframework.org

报错信息

$ robot open-chromium.robot
==============================================================================
Open-Chromium :: Open Chromium on a given URL.                                
==============================================================================
interact with browser                                                 | FAIL |
SessionNotCreatedException: Message: session not created: Chrome failed to start: exited normally.
  (session not created: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
...

原因分析及解决方案

核心原因

Snap安装的Chromium与系统默认的/usr/bin/chromium-browser路径不兼容,Selenium默认调用的系统路径无法正确启动Snap版本的Chromium;同时Snap的沙箱环境会限制DevTools端口的访问,导致无法建立会话连接。

解决步骤

  1. 指定正确的Chromium可执行路径并添加启动参数
    Snap安装的Chromium实际路径为/snap/bin/chromium,需在测试用例中明确指定该路径,同时添加参数绕过沙箱限制:
*** Settings ***
Documentation     Open Chromium on a given URL.
Library           SeleniumLibrary

*** Test Cases ***
interact with browser
    ${chrome_options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys
    ${chrome_options}.binary_location = /snap/bin/chromium
    ${chrome_options}.add_argument('--no-sandbox')
    ${chrome_options}.add_argument('--disable-dev-shm-usage')
    Open Browser    https://robotframework.org    browser=Chrome    options=${chrome_options}
    Location Should Be    https://robotframework.org
    Close Browser
  1. 匹配ChromeDriver与Chromium版本
  • 运行chromium --version查看当前Chromium版本
  • 下载对应版本的ChromeDriver,将其放入系统PATH目录,或在测试用例中指定ChromeDriver路径
  1. 验证环境
    激活虚拟环境后运行测试用例,确认浏览器能正常加载目标URL并执行后续交互操作

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 00:48:15