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

Robot Framework浏览器自动关闭问题求助(添加detach参数后异常)

解决Robot Framework中Chrome浏览器自动关闭的问题

浏览器自动关闭是因为测试执行完毕后,Selenium会默认销毁WebDriver实例,进而关闭关联的浏览器。你之前直接在Create Webdriver后加options=add_experimental_option("detach",${True})的写法错误——options参数需要接收一个完整的ChromeOptions对象,而非直接调用方法,这才导致问题恶化。

正确的修改方式如下:

*** Settings ***
Documentation    To validate the Login form
Library    SeleniumLibrary


*** Test Cases ***
Validate Unsuccessful Login
    Open The Browser With The Mortgage Payment URL
    # Fill the login form
    # Wait until it checks and displays error message
    # Verify error message is correct

*** Keywords ***
Open The Browser With The Mortgage Payment URL
    # 创建ChromeOptions对象
    ${options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys
    # 添加detach实验选项,让浏览器不随驱动销毁而关闭
    Call Method    ${options}    add_experimental_option    detach    ${True}
    # 传入配置好的options创建WebDriver
    Create Webdriver    Chrome    options=${options}
    Go To    https://rahulshettyacademy.com/loginpagePractise/

核心说明:

  • 先用Evaluate关键字创建ChromeOptions实例,需引入sys模块获取Selenium的ChromeOptions类
  • 通过Call Method调用实例的add_experimental_option方法,完成detach参数的配置
  • 最后将配置好的${options}传入Create Webdriver,即可让浏览器在测试结束后保持打开状态

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.22 02:48:12