对于测试套件,我正在运行一个使用selenium webdriver控制Firefox实例的python脚本 . 我想将about:config中的设置 dom.disable_open_during_load
更改为 true
. 虽然这是我的默认Firefox配置文件中的默认设置,但每当我'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'配置文件管理器解决问题时,selenium会将其更改为 false
(用户定义) .
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"来自哪里?它是某个地方硒的自动设置吗?我正在使用:
-
geckodriver 0.16.1
-
selenium 3.4.2 .
-
Firefox 53.0.3(64位)
-
python 3.4.4
Edit: 我刚刚在SO上找到this question,在java中处理同样的问题 .
如果事实证明这是不可能的,可能有一个很好的解决方法?有任何想法吗?
3 回答
不要使用
profile.set_preference('dom.disable_open_during_load', True)
,因为profile.default_preference
将被冻结覆盖 .profile.set_preference('dom.disable_open_during_load', True)
这是正确的方法,但它不适用于此特定属性,因为根据以下文章不允许用户更改 . 同样的事情适用于其他参数 .
即
profile.set_preference('browser.download.manager.showWhenStarting', False)
https://www.stigviewer.com/stig/mozilla_firefox/2015-06-30/finding/V-19743
Solution :
创建一个新的配置文件,并在JS文件中直接修改此设置 . 然后提供此本地配置文件的路径 . 我没有测试过这个解决方案,所以不确定它是否可行 .
出于某种原因,这种特殊设置似乎很难......
虽然我无法找到解决方案,但我受到了_2359099的启发,并使用Firefox的开发人员工具栏找到了一个不错的解决方案:
如果有人应该知道或找到更好的方法,请评论!