如何在Robot框架中使用Selenium2库向chromedriver添加扩展并远程启动

2024-10-01 17:29:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我遇到了类似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

我写了机器人测试用例如下

^{pr2}$

出现异常“init()得到意外的关键字参数'chrome\u 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,我可以添加扩展并在远程机器上启动带有扩展的浏览器。 然后我使用robot框架登录到使用python打开的扩展。所以我编写了使用robot框架关键字输入用户名和密码的步骤。在

在这里我也得到了错误'没有浏览器是打开的'。但是浏览器和扩展都是在远程机器上打开的,机器人框架无法识别它


Tags: to框架add远程def计算机extension浏览器
1条回答
网友
1楼 · 发布于 2024-10-01 17:29:37

要打开在远程服务器上加载了第三方扩展的浏览器,我使用了以下函数。它将扩展从给定的路径加载到运行selenium节点的远程服务器上的扩展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

相关问题 更多 >

    热门问题