How can I add an extension to my chromedriver at the Robot level with Selenium2Library

北城余情 提交于 2019-12-23 05:05:23

问题


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}

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.


回答1:


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

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

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}

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



来源:https://stackoverflow.com/questions/32772692/how-can-i-add-an-extension-to-my-chromedriver-at-the-robot-level-with-selenium2l

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!