如何在所需的能力中添加硒铬选项'?

时间:2017-11-02 12:42:54

标签: python google-chrome selenium

对于selenium,我有一堆chrome选项,我需要通过DesiredCapabilities传递给远程webdriver。 On this page有一个关于如何做到这一点的java示例,但是如何在python中做到这一点? documentation非常差。

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

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)

任何想法都要这样做吗?或者在哪里可以找到合适的文档?

1 个答案:

答案 0 :(得分:6)

使用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)