python - [Selenium][geckodriver] 如何更改 firefox 配置文件首选项字段,如 "security.insecure_field_warning.contextual.enabled"

标签 python selenium firefox webdriver geckodriver

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/

相关文章:

r - 无法使用 RSelenium 保存屏幕截图

java - 使用自签名 SSL 证书时,无法使用远程 Selenium WebDriver + Jenkins + FireFox 在 Java 上运行自动测试

javascript - iMacros/Firefox/格式化结果

javascript - Flash 对象在重新设计其容器样式时重新启动或消失

python - 访问 gunicorn 支持的服务时静默超时。如何调试?

python - 为什么我在安装时不断收到此消息说 EntryPoint must be in 'name=module :attrs [extras]

python - scipy gaussian_kde 根据使用的方法(权重与无权重)产生不同的结果

javascript - 如何在python-selenium中获取html元素的 'value'?

javascript - Chrome 和 Firefox 中不同的 "return null"结果

python - 是否可以使用 OpenID 在 PyPI 上上传 python 包?