本文整理汇总了Python中selenium.webdriver.firefox.options.Options.set_preference方法的典型用法代码示例。如果您正苦于以下问题:Python Options.set_preference方法的具体用法?Python Options.set_preference怎么用?Python Options.set_preference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.firefox.options.Options
的用法示例。
在下文中一共展示了Options.set_preference方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_capabilities
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import set_preference [as 别名]
def test_to_capabilities(self):
opts = Options()
assert opts.to_capabilities() == {}
profile = FirefoxProfile()
opts.profile = profile
caps = opts.to_capabilities()
assert "moz:firefoxOptions" in caps
assert "profile" in caps["moz:firefoxOptions"]
assert isinstance(caps["moz:firefoxOptions"]["profile"], basestring)
assert caps["moz:firefoxOptions"]["profile"] == profile.encoded
opts.add_argument("--foo")
caps = opts.to_capabilities()
assert "moz:firefoxOptions" in caps
assert "args" in caps["moz:firefoxOptions"]
assert caps["moz:firefoxOptions"]["args"] == ["--foo"]
binary = FirefoxBinary()
opts.binary = binary
caps = opts.to_capabilities()
assert "moz:firefoxOptions" in caps
assert "binary" in caps["moz:firefoxOptions"]
assert isinstance(caps["moz:firefoxOptions"]["binary"], basestring)
assert caps["moz:firefoxOptions"]["binary"] == binary._start_cmd
opts.set_preference("spam", "ham")
caps = opts.to_capabilities()
assert "moz:firefoxOptions" in caps
assert "prefs" in caps["moz:firefoxOptions"]
assert isinstance(caps["moz:firefoxOptions"]["prefs"], dict)
assert caps["moz:firefoxOptions"]["prefs"]["spam"] == "ham"
示例2: firefox_options
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import set_preference [as 别名]
def firefox_options(request, firefox_path, firefox_profile):
options = Options()
if firefox_profile is not None:
options.profile = firefox_profile
if firefox_path is not None:
options.binary = FirefoxBinary(firefox_path)
args = request.node.get_marker('firefox_arguments')
if args is not None:
for arg in args.args:
options.add_argument(arg)
prefs = request.node.get_marker('firefox_preferences')
if prefs is not None:
for name, value in prefs.args[0].items():
options.set_preference(name, value)
return options
示例3: test_prefs
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import set_preference [as 别名]
def test_prefs(self):
opts = Options()
assert len(opts.preferences) == 0
assert isinstance(opts.preferences, dict)
opts.set_preference("spam", "ham")
assert len(opts.preferences) == 1
opts.set_preference("eggs", True)
assert len(opts.preferences) == 2
opts.set_preference("spam", "spam")
assert len(opts.preferences) == 2
assert opts.preferences == {"spam": "spam", "eggs": True}
示例4: driver_kwargs
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import set_preference [as 别名]
def driver_kwargs(request, driver_kwargs):
options = Options()
options.set_preference('browser.startup.homepage_override.mstone', '')
options.set_preference('startup.homepage_welcome_url', 'about:')
driver_kwargs['firefox_options'] = options
return driver_kwargs