geckodriver 版本
0.16.1
Firefox 版
53.0.2(32 位)
会发生什么:
当我尝试在不安全的页面上自动登录时,firefox 打开一个新选项卡“https://support.mozilla.org/1/firefox/53.0.2/WINNT/pt-PT/insecure-password”。
如何禁用它?我认为属性“security.insecure_field_warning.contextual.enabled”与此行为有关,但我不知道如何通过 python 代码禁用它。
我尝试了以下代码但没有成功:
[...]
firefox_driver = path_drivers + "geckodriver.exe"
profile = webdriver.FirefoxProfile()
profile.set_preference("security.insecure_field_warning.contextual.enabled", False)
return webdriver.Firefox(executable_path=firefox_driver, firefox_profile=profile)
首选项不会改变,在 about:config 上保持 True 值。
有什么想法吗?
最好的问候,
鲁本桑托斯
最佳答案
我找到了解决方案。
从 geckodriver 0.11 版本开始,可以通过 moz:firefoxOptions 功能更改 firefox 首选项,而不是更改配置文件设置。
{
"capabilities": {
"alwaysMatch": {
"moz:firefoxOptions": {
"binary": "/usr/local/firefox/bin/firefox",
"args": ["--no-remote"],
"prefs": {
"dom.ipc.processCount": 8
},
"log": {
"level": "trace"
}
}
}
}
}
通过这种方式,我能够使用此解决方案更改“security.insecure_field_warning.contextual.enabled”:
[...]
firefox_driver = path_drivers + "geckodriver.exe"
firefox_capabilities = DesiredCapabilities.FIREFOX.copy()
#To disable insecure-password tab by support firefox
firefox_options = { "moz:firefoxOptions" : { "prefs" : { "security.insecure_field_warning.contextual.enabled" : False } } }
firefox_capabilities["alwaysMatch"] = firefox_options
return webdriver.Firefox(executable_path=firefox_driver, capabilities=firefox_capabilities)
关于python - [Selenium][geckodriver] 如何更改 firefox 配置文件首选项字段,如 "security.insecure_field_warning.contextual.enabled",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43875974/