本文整理汇总了Python中selenium.webdriver.firefox.options.Options类的典型用法代码示例。如果您正苦于以下问题:Python Options类的具体用法?Python Options怎么用?Python Options使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Options类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_driver
def get_driver(self,force=False):
""" セレニアムドライバ初期化 """
if force :
# 強制生成なら先にクローズしとく
self.close()
if not self.driver :
# ヘッドレスFF初期化
# UA偽造
profile = webdriver.FirefoxProfile()
profile.set_preference("general.useragent.override", self.user_agent)
# ヘッドレス定義
options = Options()
options.add_argument("--headless")
# 起動
self.driver = webdriver.Firefox(profile, firefox_options=options)
# PhantomJS初期化
# ユーザーエージェント偽装
ua = dict(DesiredCapabilities.PHANTOMJS)
ua['phantomjs.page.settings.userAgent'] = (self.user_agent)
# 初期化
#self.driver = webdriver.PhantomJS(desired_capabilities=ua) # Httpヘッダ設定
# ウェイト設定
self.driver.implicitly_wait(15) # seconds
return self.driver
示例2: _setup_firefox
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)
示例3: startMobileDriver
def startMobileDriver(self):
options = Options()
options.set_headless(self.useHeadless)
if self.loadDefaultProfile == True:
firefoxMobileProfile = webdriver.FirefoxProfile(profile_directory=self.ffProfileDir)
else:
firefoxMobileProfile = None
if self.mobileUA != None:
firefoxMobileProfile.set_preference("general.useragent.override", self.mobileUA)
self.firefoxMobileDriver = webdriver.Firefox(
firefox_profile=firefoxMobileProfile, executable_path=self.driverBinary, firefox_options=options)
self.mobileRunning = True
if self.loadCookies == True and self.cookies != None:
self.firefoxMobileDriver.delete_all_cookies()
# Loading cookies only works if we are at a site the cookie would work for
self.getMobileUrl("https://login.live.com")
for cookie in self.cookies:
# print("Adding cookie to Firefox Mobile Driver: %s" % str(cookie))
# new_cookie = {}
# new_cookie['name'] = cookie['name']
# new_cookie['value'] = cookie['value']
try:
self.firefoxMobileDriver.add_cookie(cookie)
except selenium.common.exceptions.InvalidCookieDomainException:
contine
示例4: open
def open(self):
'''
In order to have selenium working with Firefox and be able to
get SAP Notes from launchpad.support.sap.com you must:
1. Use a browser certificate (SAP Passport) in order to avoid
renewed logons.
You can apply for it at:
https://support.sap.com/support-programs-services/about/getting-started/passport.html
2. Get certificate and import it into Firefox.
Open menu -> Preferences -> Advanced -> View Certificates
-> Your Certificates -> Import
3. Trust this certificate (auto select)
4. Check it. Visit some SAP Note url in Launchpad.
No credentials will be asked.
Launchpad must load target page successfully.
'''
driver = None
utils = self.get_service('Utils')
options = Options()
options.add_argument('--headless')
FIREFOX_PROFILE_DIR = utils.get_firefox_profile_dir()
FIREFOX_PROFILE = webdriver.FirefoxProfile(FIREFOX_PROFILE_DIR)
try:
driver = webdriver.Firefox(firefox_profile=FIREFOX_PROFILE, firefox_options=options)
except Exception as error:
self.log.error(error)
# Geckodriver not found
# Download it from:
# https://github.com/mozilla/geckodriver/releases/latest
self.log.debug("Webdriver initialited")
return driver
示例5: getCDMStatusPage
def getCDMStatusPage(tid_crm):
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument("--headless")
browser = webdriver.Firefox(firefox_options=options)
# now Firefox will run headless
# you will not see the browser.
link = 'http://172.18.65.42/monitorcdm/'
browser.get(link)
browser.find_elements_by_css_selector("input[type='radio'][value='GUEST']")[0].click()
browser.find_element_by_class_name('tbutton').click()
browser.get(link)
browser.get('http://172.18.65.42/monitorcdm/?_module_=search_tid')
form_textfield = browser.find_element_by_name('_termid_')
form_textfield.send_keys(tid_crm)
browser.find_element_by_class_name('tbutton').click()
html = browser.page_source
browser.quit()
return html
示例6: start_driver
def start_driver(self, browser_type, capabilities, config_section=None):
""" Prepare selenium webdriver.
:param browser_type: type of browser for which prepare driver
:param capabilities: capabilities used for webdriver initialization
"""
# get browser profile
browser_profile = self.get_browser_profile(browser_type, capabilities, config_section)
# starts local browser
if browser_type == "firefox":
from selenium.webdriver.firefox.options import Options
firefox_options = Options()
for arg in self.get_browser_arguments(config_section):
firefox_options.add_argument(arg)
driver = webdriver.Firefox(browser_profile, desired_capabilities=capabilities,
firefox_options=firefox_options)
elif browser_type == "chrome":
driver = webdriver.Chrome(desired_capabilities=capabilities, chrome_options=browser_profile)
elif browser_type == "ie":
driver = webdriver.Ie(capabilities=capabilities)
elif browser_type == "phantomjs":
driver = webdriver.PhantomJS(desired_capabilities=capabilities)
elif browser_type == "opera":
driver = webdriver.Opera(desired_capabilities=capabilities)
# SafariDriver bindings for Python not yet implemented
# elif browser == "Safari":
# self.driver = webdriver.SafariDriver()
else:
raise ValueError('Unknown type of browser.')
return driver
示例7: initialize_browser
def initialize_browser(for_scenario_2=False):
browser = None
if for_scenario_2:
# Test Scenario 2 requires users to download things from their browser.
# Define a custom profile for Firefox, to automatically download files that a page asks user to download, without asking. This is because Selenium can't control downloads.
profile = webdriver.FirefoxProfile()
profile.set_preference('browser.download.folderList', 2) # Can be set to either 0, 1, or 2. When set to 0, Firefox will save all files downloaded via the browser on the user's desktop. When set to 1, these downloads are stored in the Downloads folder. When set to 2, the location specified for the most recent download is utilized again.
profile.set_preference('browser.download.manager.showWhenStarting', False)
profile.set_preference('browser.download.dir', settings.BROWSER_DOWNLOAD_FOLDER)
mime_types_that_should_be_downloaded = ['text/plain', 'application/json']
profile.set_preference('browser.helperApps.neverAsk.saveToDisk', ';'.join(mime_types_that_should_be_downloaded))
if settings.USE_HEADLESS_BROWSER:
from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument("--headless")
options.log.level = "trace"
if for_scenario_2:
browser = webdriver.Firefox(profile, options=options)
else:
browser = webdriver.Firefox(options=options)
else:
if for_scenario_2:
browser = webdriver.Firefox(profile)
else:
browser = webdriver.Firefox()
# browser.maximize_window() # make the browser window use all available screen space. FIXME: When enabled, some clicks are not triggered anymore
browser.implicitly_wait(settings.WAIT_TIME_BETWEEN_EACH_STEP) # In seconds
return browser
示例8: setUp
def setUp(self):
if _CI:
self.driver = self.sauce_chrome_webdriver()
elif settings.SELENIUM is True:
options = FirefoxOptions()
options.add_argument('-headless')
self.driver = Firefox(firefox_options=options)
self.driver.implicitly_wait(10)
示例9: load_driver
def load_driver():
"""
Loads the firefox driver in headless mode.
"""
options = Options()
options.add_argument("--headless")
driver = webdriver.Firefox(firefox_options=options)
return driver
示例10: setUp
def setUp(self):
superuser = User.objects.create_superuser(self.username, '[email protected]', self.password)
self.existing = TestModel.objects.get(pk=1)
# Instantiating the WebDriver will load your browser
options = Options()
if settings.HEADLESS_TESTING:
options.add_argument("--headless")
self.webdriver = CustomWebDriver(firefox_options=options, )
示例11: setUpClass
def setUpClass(cls):
super(LiveTestCase, cls).setUpClass()
options = Options()
options.headless = True
cls.selenium = WebDriver(options=options)
cls.selenium.implicitly_wait(10)
示例12: test_arguments
def test_arguments(self):
opts = Options()
assert len(opts.arguments) == 0
opts.add_argument("--foo")
assert len(opts.arguments) == 1
opts.arguments.append("--bar")
assert len(opts.arguments) == 2
assert opts.arguments == ["--foo", "--bar"]
示例13: setUp
def setUp(self):
# Firefox
options_firefox = OptionsFF()
options_firefox.add_argument('-headless')
self.firefox_driver = webdriver.Firefox(firefox_options=options_firefox)
# Chrome
options_chrome = OptionsChrom()
options_chrome.add_argument('-headless')
self.chrome_driver = webdriver.Chrome(chrome_options=options_chrome)
示例14: test_rendering_utf8_iframe
def test_rendering_utf8_iframe():
iframe = elem.IFrame(html=u'<p>Cerrahpaşa Tıp Fakültesi</p>')
options = Options()
options.add_argument('-headless')
driver = Firefox(options=options)
driver.get('data:text/html,' + iframe.render())
driver.switch_to.frame(0)
assert u'Cerrahpaşa Tıp Fakültesi' in driver.page_source
示例15: setUp
def setUp(self):
options = Options()
options.add_argument('-headless')
self.browser = webdriver.Firefox(options=options)
self.browser.get(redbot_uri)
self.uri = self.browser.find_element_by_id("uri")
self.uri.send_keys(self.test_uri)
self.uri.submit()
time.sleep(2.0)
self.check_complete()