首页 文章

机器人框架: - 无法从现有Chrome配置文件打开Chrome

提问于
浏览
1

我正在努力学习机器人框架 . 我已经在Selenium Webdriver上工作了 . 我尝试使用“创建Webdriver关键字”从“退出配置文件”中打开Chrome浏览器 . 但是我无法做到 . 它似乎机器人框架每次都会打开一个新的Chrome配置文件 . 这是我在goggling之后得到的代码,但这不是我喜欢的用户数据文件夹中的Chrome . 任何建议或想法都可以实现 .

Open Chrome Using Create WebDriver Keyword
[Tags]  chrome
${options}=  Evaluate  sys.modules['selenium.webdriver'].ChromeOptions()  sys, selenium.webdriver
${options.add_argument}=  Set Variable  --allow-running-insecure-content
${options.add_argument}=  Set Variable  --disable-web-security
${options.add_argument}=  Set Variable  user-data-dir = /Users/myName/AppData/Local/Google/Chrome/User Data
Create WebDriver  Chrome  chrome_options=${options}
go to  {URL}

#关闭浏览器

1 回答

  • 0

    要添加参数,请调用ChromeOptions对象的add_argument方法 . 请注意,您需要在--user-data-dir参数中转义'=',否则Robot Framework将查找名为'--user-data-dir'的参数并失败 . 在测试时,我注意到如果配置文件不存在,将在指定的位置创建配置文件 .

    Open Chrome Using Create WebDriver Keyword
        ${options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()    sys, selenium.webdriver
        Call Method    ${options}    add_argument    --allow-running-insecure-content
        Call Method    ${options}    add_argument    --disable-web-security
        Call Method    ${options}    add_argument    --user-data-dir\=/Users/myName/AppData/Local/Google/Chrome/User Data
        Create WebDriver    Chrome    chrome_options=${options}
        Go To    https://stackoverflow.com
    

相关问题