Selenium:Firefox Webdriver的about:config中的布尔设置 [英] Selenium: boolean setting in about:config of Firefox webdriver
问题描述
对于一个测试套件,我正在运行一个使用selenium webdriver控制Firefox实例的python脚本.我想将about:config中的设置dom.disable_open_during_load
更改为true
.尽管这是默认Firefox配置文件中的默认设置,但是每当我启动Webdriver实例时,selenium都会将其更改为false
(用户定义).似乎使用的是匿名的,略有更改的个人资料?!然后,我可以手动将其改回,但是我却在用代码来解决这一问题:既不使用新的配置文件,也不使用通过Firefox的配置文件管理器配置的预设配置文件即可解决此问题.
For a test suite, I'm running a python script controlling a Firefox instance using selenium webdriver. I want to change the setting dom.disable_open_during_load
in about:config to true
. Although this is the default setting in my default Firefox profile, selenium changes it to false
(user-defined) whenever I'm starting a webdriver instance. It seems to use an anonymous, slightly changed profile?! I can then manually change it back, but I was struggling to do it with code: neither using a new profile nor using a pre-set profile configured with Firefox' profile manager solves the problem.
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
用户定义"来自何处?它是硒自动设置的地方吗?我正在使用:
I can change various settings this way, but it doesn't work for this one. Where does the changed value false
"user-defined" come from? Is it an automatic setting of selenium somewhere? I'm using:
- geckodriver 0.16.1
- 硒3.4.2.
- Firefox 53.0.3(64位)
- python 3.4.4
I just found this question on SO, dealing with the same problem in java.
如果事实证明这是不可能的,那么可能有一个不错的解决方法?有什么想法吗?
If this turns out to be impossible, probably there is a nice work-around? Any ideas?
推荐答案
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
将被冻结的覆盖.
Don't use profile.set_preference('dom.disable_open_during_load', True)
as profile.default_preference
will be overrided by frozen's.
这篇关于Selenium:Firefox Webdriver的about:config中的布尔设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!