本文整理汇总了Python中selenium.webdriver.firefox.options.Options.add_argument方法的典型用法代码示例。如果您正苦于以下问题:Python Options.add_argument方法的具体用法?Python Options.add_argument怎么用?Python Options.add_argument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.firefox.options.Options
的用法示例。
在下文中一共展示了Options.add_argument方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: initialize_browser
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import add_argument [as 别名]
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
示例2: get_driver
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import add_argument [as 别名]
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
示例3: test_to_capabilities
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import add_argument [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"
示例4: start_driver
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import add_argument [as 别名]
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
示例5: getCDMStatusPage
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import add_argument [as 别名]
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: _setup_firefox
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import add_argument [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)
示例7: open
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import add_argument [as 别名]
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
示例8: load_driver
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import add_argument [as 别名]
def load_driver():
"""
Loads the firefox driver in headless mode.
"""
options = Options()
options.add_argument("--headless")
driver = webdriver.Firefox(firefox_options=options)
return driver
示例9: setUp
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import add_argument [as 别名]
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)
示例10: setUp
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import add_argument [as 别名]
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: setUp
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import add_argument [as 别名]
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)
示例12: test_arguments
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import add_argument [as 别名]
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: test_rendering_utf8_iframe
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import add_argument [as 别名]
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
示例14: setUp
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import add_argument [as 别名]
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()
示例15: new_instance
# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import add_argument [as 别名]
def new_instance(self):
""" initializes a new selenium web driver instance by using either PhantomJS or Mozilla
and returns a reference to the browser object for further processing """
options = Options()
if self.headless:
print_debug(self.debug, 'actiating headless mode')
options.add_argument('-headless')
driver = webdriver.Firefox(firefox_options=options)
driver.set_window_size(1024, 768)
driver.set_script_timeout(5)
return driver