gpt4 book ai didi

python - Selenium: about:config of Firefox webdriver 中的 boolean 设置

转载 作者:行者123 更新时间:2023-11-28 20:36:49 25 4
gpt4 key购买 nike

对于测试套件,我正在运行一个使用 selenium webdriver 控制 Firefox 实例的 python 脚本。我想将 about:config 中的设置 dom.disable_open_during_load 更改为 true。尽管这是我的默认 Firefox 配置文件中的默认设置,但每当我启动 webdriver 实例时,selenium 都会将其更改为 false(用户定义)。它似乎使用了一个匿名的,略有变化的配置文件?!然后我可以手动将其更改回来,但我很难用代码来做到这一点:无论是使用新的配置文件还是使用通过 Firefox 的配置文件管理器配置的预设配置文件都无法解决问题。

from selenium import webdriver

FFprofile = webdriver.FirefoxProfile()
FFprofile.set_preference('dom.disable_open_during_load', 'true') # I also tried True, 1 - with and without quotes
# FFprofile = webdriver.FirefoxProfile('C:/Users/ExampleUser/AppData/Local/Mozilla/Firefox/Profiles/owieroiuysd.testprofile')


FFdriver = webdriver.Firefox(firefox_profile=FFprofile)
FFdriver.get('http://www.google.com')

我可以通过这种方式更改各种设置,但它不适用于这个。更改后的值false“user-defined”从何而来?它是在某处自动设置 Selenium 吗?我正在使用:

  • 壁虎驱动程序 0.16.1
  • Selenium 3.4.2。
  • Firefox 53.0.3(64 位)
  • python 3.4.4

编辑:我刚找到this question在 SO 上,处理 java 中的相同问题。

如果事实证明这是不可能的,可能有一个很好的解决方法?有什么想法吗?

最佳答案

fp = webdriver.FirefoxProfile()
fp.DEFAULT_PREFERENCES['frozen']["dom.disable_open_during_load"] = True

不要使用 profile.set_preference('dom.disable_open_during_load', True) 因为 profile.default_preference 会被 frozen 的覆盖。

关于python - Selenium: about:config of Firefox webdriver 中的 boolean 设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44277519/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com