如何将selenium铬选项添加到“ desiredCapabilities”?

对于selenium,我有很多用于chrome的选项,我需要通过将该选项传递给远程webdriver

DesiredCapabilities。在此页面上,有一个有关如何执行此操作的Java示例,但是如何在python中执行此操作?该文档非常差。

这是我到目前为止的代码:

prefs = {

"profile.default_content_settings.popups":0,

"download.prompt_for_download": "false",

"download.default_directory": cwd,

}

chrome_options = Options()

chrome_options.add_argument("--disable-extensions")

chrome_options.add_experimental_option("prefs", prefs)

capabilities = DesiredCapabilities.CHROME

#code I could not find

#I need something like

#capabilities.add_options(chrome_options)

driver = webdriver.Remote(

command_executor='http://aaa.bbb.ccc:4444/wd/hub',

desired_capabilities=capabilities)

知道要这样做吗?还是在哪里可以找到适当的文档?

回答:

用于options.to_capabilities()从选项中获取功能:

options = webdriver.ChromeOptions()

options.add_argument("--headless")

options.add_argument("--disable-gpu")

capabilities = options.to_capabilities()

driver = webdriver.Remote( \

command_executor='http://127.0.0.1:4444/wd/hub', \

desired_capabilities=capabilities)

以上是 如何将selenium铬选项添加到“ desiredCapabilities”? 的全部内容, 来源链接: utcz.com/qa/414332.html

回到顶部