我陷入了像 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 打开的扩展。所以我编写了使用机器人框架关键字输入用户名和密码的步骤。
在这里我也遇到了错误“没有打开浏览器”。但是浏览器和扩展程序都在远程计算机上打开,机器人框架无法识别它
最佳答案
要打开远程服务器上加载第三方扩展的浏览器,我使用了以下功能。它从运行 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
关于python - 如何使用 Selenium2Library 在 Robot Framework 上向 chromedriver 添加扩展并远程启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33693822/