本文整理汇总了Python中selenium.webdriver.firefox.options.Options.profile方法的典型用法代码示例。如果您正苦于以下问题:Python Options.profile方法的具体用法?Python Options.profile怎么用?Python Options.profile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.firefox.options.Options
的用法示例。
在下文中一共展示了Options.profile方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_profile
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import profile [as 别名]
def test_profile(self, tmpdir_factory):
opts = Options()
assert opts.profile is None
other_profile = FirefoxProfile()
assert other_profile != opts.profile
opts.profile = other_profile
assert other_profile == opts.profile
opts.profile = str(tmpdir_factory.mktemp("profile"))
assert isinstance(opts.profile, FirefoxProfile)
示例2: test_to_capabilities
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import profile [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: driver_kwargs
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import profile [as 别名]
def driver_kwargs(request, driver_kwargs, profile):
if request.param == 'capabilities':
options = {'profile': profile}
driver_kwargs[request.param].setdefault('moz:firefoxOptions', options)
elif request.param == 'firefox_profile':
driver_kwargs[request.param] = profile
elif request.param == 'firefox_options':
options = Options()
options.profile = profile
driver_kwargs[request.param] = options
driver_kwargs['firefox_profile'] = profile
return driver_kwargs
示例4: create_instances_of_webdriver
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import profile [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 profile [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: __init__
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import profile [as 别名]
def __init__(self, client="firefox", username="API", proxy=None, command_executor=None, loadstyles=False,
profile=None, headless=False, autoconnect=True, logger=None, extra_params=None, chrome_options=None):
"""Initialises the webdriver"""
self.logger = logger or self.logger
extra_params = extra_params or {}
if profile is not None:
self._profile_path = profile
self.logger.info("Checking for profile at %s" % self._profile_path)
if not os.path.exists(self._profile_path):
self.logger.critical("Could not find profile at %s" % profile)
raise WhatsAPIException("Could not find profile at %s" % profile)
else:
self._profile_path = None
self.client = client.lower()
if self.client == "firefox":
if self._profile_path is not None:
self._profile = webdriver.FirefoxProfile(self._profile_path)
else:
self._profile = webdriver.FirefoxProfile()
if not loadstyles:
# Disable CSS
self._profile.set_preference('permissions.default.stylesheet', 2)
# Disable images
self._profile.set_preference('permissions.default.image', 2)
# Disable Flash
self._profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so',
'false')
if proxy is not None:
self.set_proxy(proxy)
options = Options()
if headless:
options.set_headless()
options.profile = self._profile
capabilities = DesiredCapabilities.FIREFOX.copy()
capabilities['webStorageEnabled'] = True
self.logger.info("Starting webdriver")
self.driver = webdriver.Firefox(capabilities=capabilities, options=options, **extra_params)
elif self.client == "chrome":
self._profile = webdriver.ChromeOptions()
if self._profile_path is not None:
self._profile.add_argument("user-data-dir=%s" % self._profile_path)
if proxy is not None:
self._profile.add_argument('--proxy-server=%s' % proxy)
if headless:
self._profile.add_argument('headless')
if chrome_options is not None:
for option in chrome_options:
self._profile.add_argument(option)
self.logger.info("Starting webdriver")
self.driver = webdriver.Chrome(chrome_options=self._profile, **extra_params)
elif client == 'remote':
if self._profile_path is not None:
self._profile = webdriver.FirefoxProfile(self._profile_path)
else:
self._profile = webdriver.FirefoxProfile()
capabilities = DesiredCapabilities.FIREFOX.copy()
self.driver = webdriver.Remote(
command_executor=command_executor,
desired_capabilities=capabilities,
**extra_params
)
else:
self.logger.error("Invalid client: %s" % client)
self.username = username
self.wapi_functions = WapiJsWrapper(self.driver, self)
self.driver.set_script_timeout(500)
self.driver.implicitly_wait(10)
if autoconnect:
self.connect()