本文整理汇总了Python中selenium.webdriver.firefox.options.Options.binary方法的典型用法代码示例。如果您正苦于以下问题:Python Options.binary方法的具体用法?Python Options.binary怎么用?Python Options.binary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.firefox.options.Options
的用法示例。
在下文中一共展示了Options.binary方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_binary
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import binary [as 别名]
def test_binary(self):
opts = Options()
assert opts.binary is None
other_binary = FirefoxBinary()
assert other_binary != opts.binary
opts.binary = other_binary
assert other_binary == opts.binary
path = "/path/to/binary"
opts.binary = path
assert isinstance(opts.binary, FirefoxBinary)
assert opts.binary._start_cmd == path
示例2: test_to_capabilities
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import binary [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"
示例3: _setup_firefox
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import binary [as 别名]
def _setup_firefox(self, capabilities):
"""Setup Firefox webdriver
:param capabilities: capabilities object
:returns: a new local Firefox driver
"""
if capabilities.get("marionette"):
gecko_driver = self.config.get('Driver', 'gecko_driver_path')
self.logger.debug("Gecko driver path given in properties: %s", gecko_driver)
else:
gecko_driver = None
# Get Firefox binary
firefox_binary = self.config.get_optional('Firefox', 'binary')
firefox_options = Options()
if self.config.getboolean_optional('Driver', 'headless'):
self.logger.debug("Running Firefox in headless mode")
firefox_options.add_argument('-headless')
self._add_firefox_arguments(firefox_options)
if firefox_binary:
firefox_options.binary = firefox_binary
log_path = os.path.join(DriverWrappersPool.output_directory, 'geckodriver.log')
try:
# Selenium 3
return webdriver.Firefox(firefox_profile=self._create_firefox_profile(), capabilities=capabilities,
executable_path=gecko_driver, firefox_options=firefox_options, log_path=log_path)
except TypeError:
# Selenium 2
return webdriver.Firefox(firefox_profile=self._create_firefox_profile(), capabilities=capabilities,
executable_path=gecko_driver, firefox_options=firefox_options)
示例4: create_instances_of_webdriver
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import binary [as 别名]
def create_instances_of_webdriver(selenium, driver, browser_id_list, tmpdir,
tmp_memory, driver_kwargs, driver_type,
firefox_logging, firefox_path, xvfb,
screen_width, screen_height, displays):
for browser_id, display in zip(parse_seq(browser_id_list), cycle(xvfb)):
if browser_id in selenium:
raise AttributeError('{:s} already in use'.format(browser_id))
else:
tmp_memory[browser_id] = {'shares': {},
'spaces': {},
'groups': {},
'mailbox': {},
'oz': {},
'window': {'modal': None}}
with redirect_display(display):
temp_dir = str(tmpdir)
download_dir = os.path.join(temp_dir, browser_id, 'download')
if driver_type.lower() == 'chrome':
options = driver_kwargs['desired_capabilities']['chromeOptions']
prefs = {"download.default_directory": download_dir}
options['prefs'].update(prefs)
elif driver_type.lower() == 'firefox':
options = Options()
profile = FirefoxProfile()
log_path = _set_firefox_profile(profile, browser_id,
temp_dir, firefox_logging)
options.profile = profile
if firefox_path is not None:
options.binary = FirefoxBinary(firefox_path)
driver_kwargs['firefox_options'] = options
browser = driver(driver_kwargs)
if driver_type.lower() == 'firefox' and firefox_logging:
browser.get_log = _firefox_logger(log_path)
_config_driver(browser, screen_width, screen_height)
displays[browser_id] = display
selenium[browser_id] = browser
示例5: firefox_options
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import binary [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
示例6: _setup_firefox
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import binary [as 别名]
def _setup_firefox(self, capabilities):
"""Setup Firefox webdriver
:param capabilities: capabilities object
:returns: a new local Firefox driver
"""
if capabilities.get("marionette"):
gecko_driver = self.config.get('Driver', 'gecko_driver_path')
self.logger.debug("Gecko driver path given in properties: {0}".format(gecko_driver))
else:
gecko_driver = None
# Get Firefox binary
firefox_binary = self.config.get_optional('Firefox', 'binary')
if firefox_binary:
self.logger.debug("Using firefox binary: {0}".format(firefox_binary))
firefox_options = Options()
firefox_options.binary = firefox_binary
else:
firefox_options = None
return webdriver.Firefox(firefox_profile=self._create_firefox_profile(), capabilities=capabilities,
executable_path=gecko_driver, firefox_options=firefox_options)