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

如何在Robot Framework中禁用Chrome的“由自动化测试软件控制”提示?

在Robot Framework中禁用Chrome自动化控制提示栏的解决方法

完全可以禁用这个提示栏,核心是通过Chrome的启动参数和实验选项来配置,以下是两种可靠的实现方式:

方法一:通过ChromeOptions对象配置(推荐)

这种方式更直观,便于扩展其他Chrome配置:

*** Settings ***
Library    SeleniumLibrary

*** Test Cases ***
Disable Chrome Automation Info Bar
    # 初始化ChromeOptions对象
    ${chrome_options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys
    # 添加禁用信息栏的参数
    Call Method    ${chrome_options}    add_argument    --disable-infobars
    # 移除自动化标识开关,避免触发提示
    Call Method    ${chrome_options}    add_experimental_option    excludeSwitches    ['enable-automation']
    # 禁用Selenium自动化扩展
    Call Method    ${chrome_options}    add_experimental_option    useAutomationExtension    ${False}
    # 针对新版Chrome,额外添加绕过自动化检测的参数
    Call Method    ${chrome_options}    add_argument    --disable-blink-features=AutomationControlled
    
    # 启动Chrome浏览器
    Create Webdriver    Chrome    chrome_options=${chrome_options}
    Go To    https://www.example.com
    # 执行你的测试步骤
    Close Browser

方法二:通过Desired Capabilities字典配置

如果偏好直接构造字典传递配置,可以用这种方式:

*** Settings ***
Library    SeleniumLibrary

*** Test Cases ***
Disable Automation Prompt
    ${desired_caps}=    Create Dictionary
    # 构造Chrome配置参数
    ${chrome_config}=    Create Dictionary
    Set To Dictionary    ${chrome_config}    excludeSwitches    ['enable-automation']
    Set To Dictionary    ${chrome_config}    useAutomationExtension    ${False}
    Set To Dictionary    ${chrome_config}    args    ['--disable-infobars', '--disable-blink-features=AutomationControlled']
    Set To Dictionary    ${desired_caps}    chromeOptions    ${chrome_config}
    
    # 启动浏览器
    Create Webdriver    Chrome    desired_capabilities=${desired_caps}
    Go To    https://www.example.com
    Close Browser

关键参数说明

  • --disable-infobars:直接关闭顶部的信息提示栏
  • excludeSwitches: ['enable-automation']:移除Chrome的自动化标识,避免被检测为自动化工具
  • useAutomationExtension: false:禁用Selenium自带的自动化扩展,防止触发提示
  • --disable-blink-features=AutomationControlled:针对Chrome 79及以上版本,绕过新增的自动化检测机制

注意事项

  • 确保Chrome浏览器和ChromeDriver版本严格匹配,版本不兼容会导致配置参数失效
  • 如果仍有提示,检查是否有其他扩展或浏览器设置干扰,可尝试在无痕模式下启动(添加--incognito参数)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 10:12:51