如何将硒铬选项添加到"desiredCapabilities"? [英] How to add selenium chrome options to 'desiredCapabilities'?
本文介绍了如何将硒铬选项添加到"desiredCapabilities"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于硒,我有很多用于chrome的选项,我需要通过DesiredCapabilities
传递给远程webdriver. 在此页面上有一个有关如何执行此操作的Java示例,但是如何在python中做到这一点?
For selenium I have a bunch of options for chrome, which I need to pass to the remote webdriver via DesiredCapabilities
. On this page there is a java example on how to do this, but how to do it in python? The documentation is very poor.
这是我到目前为止的代码:
Here is the code I have so far:
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)
有什么想法可以做到这一点吗?还是在哪里可以找到适当的文档?
Any idea ho to do this? Or where to find proper documentation?
推荐答案
使用options.to_capabilities()
从选项中获取功能:
Use options.to_capabilities()
to get the capabilities from the options:
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)
这篇关于如何将硒铬选项添加到"desiredCapabilities"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文