【问题标题】:How can I add an extension to my chromedriver at the Robot Framework with Selenium2Library and launch remotely如何使用 Selenium2Library 在 Robot Framework 中向我的 chromedriver 添加扩展并远程启动
【发布时间】:2016-02-15 02:21:40
【问题描述】:

我遇到了How can I add an extension to my chromedriver at the Robot level with Selenium2Library 之类的场景,但我正在尝试在远程机器上启动浏览器。

上述问题的答案在本地机器上运行良好。但是如何向 chrome 浏览器添加扩展并在远程机器上启动。

使用python获取chrome选项

def launchbrowserwithextension():
options = webdriver.ChromeOptions()
options.add_argument('--load-and-launch-app=path_to_extension')
return chrome_options

我写的机器人测试用例如下

${options}=    launchbrowserwithextension
${executor}=    Evaluate    str('http://xx.xx.xx.xx:5558/wd/hub')
${desired capabilities}=    Evaluate    { "browserName": "chrome", "version": "", "platform": "VISTA", "javascriptEnabled": True}
Create Webdriver    Remote    desired_capabilities=${desired capabilities}    command_executor=${executor}    chrome_options=${options}

得到异常“init() 得到了一个意外的关键字参数 'chrome_options'”

其次,我尝试了以下

def launchbrowserwithextension():
options = webdriver.ChromeOptions()
options.add_argument('--load-and-launch-app=path_to_extension')
driver = webdriver.Remote('http://xx.xx.xx.xx:5558/wd/hub', options.to_capabilities())

使用 python,我可以在带有扩展名的远程机器上添加扩展名并启动浏览器。 然后我使用机器人框架登录到使用 python 打开的扩展。所以我写了使用机器人框架关键字输入用户名和密码的步骤。

在这里,我最终也收到错误“没有打开浏览器”。但是浏览器和扩展程序都是在远程机器上打开的,机器人框架无法识别它

【问题讨论】:

标签: python selenium selenium-webdriver robotframework selenium-chromedriver


【解决方案1】:

要在远程服务器上打开加载了第三方扩展的浏览器,我使用了以下功能。它从运行 selenium 节点的远程服务器上的给定 path_to_extension 加载扩展。 url 应该是 selenium 节点运行的路径。最后返回实例ID

openBrowserWithExtension
        options = webdriver.ChromeOptions()
        options.add_argument('--load-and-launch-app=path_to_extension')
        capabilities = webdriver.DesiredCapabilities()
        instance = BuiltIn().get_library_instance('Selenium2Library').create_webdriver('Remote', command_executor=url, desired_capabilities=options.to_capabilities())      
        return instance

【讨论】:

    猜你喜欢
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-14
    • 2015-09-14
    • 2015-08-12
    • 1970-01-01
    相关资源
    最近更新 更多