gpt4 book ai didi

python - RobotFramework - 通过 Open Browser 关键字添加 chrome 扩展

转载 作者:行者123 更新时间:2023-12-04 17:35:55 27 4
gpt4 key购买 nike

我正在尝试向机器人框架添加一个 chrome 扩展。我正在使用关键字 Open Browser(通过添加 desired_capabilities),但是当我运行这段代码时,没有添加任何扩展(但没有发生错误)。我检查了 crx 文件的路径,它应该是正确的。

*** Settings ***
Library SeleniumLibrary
Library Process
Library Collections
Suite Teardown Close Browser

***Variables***
${BROWSER} Chrome
${SELENIUM} http://hub:4444/wd/hub

*** Test Cases ***
Open Chrome with extension

${options} = Create List add_extension ${CURDIR}/office-extension.crx
${arguments} = Create Dictionary args=${options}
${capabilities} = Create Dictionary chromeOptions=${arguments}

Open Browser chrome://extensions/ remote_url=${SELENIUM} browser=${BROWSER} desired_capabilities=${capabilities}
Capture Page Screenshot

最佳答案

这对我有用:

   *** Test Cases ***
Open Chrome with extension
${ChromeOptions} = Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${ChromeOptions} add_argument remote-debugging-port\=9222
Call Method ${ChromeOptions} add_argument ${args}
Call Method ${ChromeOptions} add_extension ${EXECDIR}${/}Resources${/}BrowserAddons${/}test1.crx
${Options}= Call Method ${ChromeOptions} to_capabilities
Create Webdriver Chrome desired_capabilities=${Options}
Go to about:blank
Maximize Browser Window

这里用open Browser关键字

Open Chrome with extension
${ChromeOptions} = Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${ChromeOptions} add_argument remote-debugging-port\=9222
Call Method ${ChromeOptions} add_argument ${args}
Call Method ${ChromeOptions} add_extension ${EXECDIR}{/}test1.crx
${Options}= Call Method ${ChromeOptions} to_capabilities
Open Browser about:blank Chrome desired_capabilities=${Options}
Maximize Browser Window

您不必使用 remote-debugging-port\=9222,这是我必须做的事情,否则 chrome 不会。

关于python - RobotFramework - 通过 Open Browser 关键字添加 chrome 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56584420/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com