问题
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