如何使用 Selenium2Library 在机器人级别向我的 chromedriver 添加扩展 [英] How can I add an extension to my chromedriver at the Robot level with Selenium2Library

查看:47
本文介绍了如何使用 Selenium2Library 在机器人级别向我的 chromedriver 添加扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的机器人套件设置中实例化一个 chromedriver 实例,但我需要在浏览器启动时安装一个扩展程序.我可以通过简单地将 chromeoptions 添加到我的 webdriver instatiation 来轻松地在 Python 级别执行此操作,但我需要在机器人级别执行此操作.我发现有一个关键字Create Webdriver"允许您将参数传递到您的 webdriver 实例中.但是,我仍然无法在启动时安装扩展.我正在使用来自 selenium.webdriver.chrome.options 和函数 add_extension 的选项.任何人都可以帮我解决这个问题吗?

I would like to instantiate a chromedriver instance in my Robot suite setup but I need to install an extension upon browser startup. I'm able to easily do this at the Python level by simply adding chromeoptions to my webdriver instatiation, but I need to do this at the Robot level. I found that there IS a keyword "Create Webdriver" that allows you to pass arguments into your webdriver instantiation. However, I still cannot get an extension to install at startup. I am using Options from selenium.webdriver.chrome.options and the function add_extension. Can anyone please help me with this?

Some_Setup
    ${options}=    Evaluate    sys.modules['selenium.webdriver'].ChromeOptions()       sys, selenium.webdriver.chrome.options
    ${options.add_extension}=        Set_Variable          path/to/extension
    Create WebDriver    Chrome    chrome_options=${options}

如果有一种方法可以通过所需的功能传入我的扩展程序,我将如何在字典中对其进行格式化?似乎desired_capabilties 有一个带有args:[] 和extensions:[] 字段的chromeOptions 字段,但我不知道如何将我的扩展名传递给它.

If there is a way to pass in my extension via desired capabilities, how would I format that in a dictionary? It seems like desired_capabilties has a chromeOptions field with an args:[] and extensions:[] fields avaialable but I don't know how to pass my extension to it.

推荐答案

Using Options from selenium.webdriver.chrome.options, 在 Python 中使用

Using Options from selenium.webdriver.chrome.options, add the extension in Python using

options = Options()
options.add_extension(path-to-extension)

返回 Options 对象,将其保存到 ${chrome_options} 变量中,然后...

return the Options object, save it into the ${chrome_options} variable, and then...

${kwargs}=          Create Dictionary        chrome_options=${chrome_options}
Create Webdriver    Chrome                   kwargs=${kwargs}

请注意,机器人测试套件必须导入定义了上述get_options"函数的 python 库.

Note the the robot test suite must import the python lib that defines some "get_options" function as above.

这篇关于如何使用 Selenium2Library 在机器人级别向我的 chromedriver 添加扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆