當前位置: 首頁>>代碼示例>>Python>>正文


Python Options.add_argument方法代碼示例

本文整理匯總了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
開發者ID:glondu,項目名稱:belenios,代碼行數:32,代碼來源:election_testing.py

示例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
開發者ID:henpin,項目名稱:module,代碼行數:30,代碼來源:selenium_loader.py

示例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"
開發者ID:juangj,項目名稱:selenium,代碼行數:34,代碼來源:mn_options_tests.py

示例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
開發者ID:salsita,項目名稱:shishito,代碼行數:35,代碼來源:local.py

示例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
開發者ID:jansenicus,項目名稱:python-scripts,代碼行數:28,代碼來源:fetchStatusCRM.py

示例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)
開發者ID:jframos,項目名稱:toolium,代碼行數:37,代碼來源:config_driver.py

示例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
開發者ID:t00m,項目名稱:basico,代碼行數:33,代碼來源:srv_driver.py

示例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
開發者ID:amustafa,項目名稱:recovering-incomplete-monero-mnemonic,代碼行數:10,代碼來源:seeds_to_addresses.py

示例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)
開發者ID:dan-brown,項目名稱:RiddleBase,代碼行數:10,代碼來源:base.py

示例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, )
開發者ID:benzkji,項目名稱:django-ckeditor-link,代碼行數:10,代碼來源:test_editor.py

示例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)
開發者ID:adsabs,項目名稱:tugboat,代碼行數:11,代碼來源:test_selenium.py

示例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"]
開發者ID:juangj,項目名稱:selenium,代碼行數:11,代碼來源:mn_options_tests.py

示例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
開發者ID:ocefpaf,項目名稱:branca,代碼行數:12,代碼來源:test_iframe.py

示例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()
開發者ID:plambert,項目名稱:redbot,代碼行數:12,代碼來源:test_webui.py

示例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
開發者ID:grindsa,項目名稱:o2_scrap,代碼行數:13,代碼來源:o2_scrap.py


注:本文中的selenium.webdriver.firefox.options.Options.add_argument方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。