![](/img/trans.png)
[英]How can I add an extension to my chromedriver at the Robot level with Selenium2Library
[英]How can I add an extension to my chromedriver at the Robot Framework with Selenium2Library and launch remotely
我遇到了諸如如何使用 Selenium2Library 在機器人級別向我的 chromedriver 添加擴展這樣的場景,但我正在嘗試在遠程計算機上啟動瀏覽器。
上述問題的答案在本地機器上運行良好。 但是如何向 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.