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


Python options.Options類代碼示例

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

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

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

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

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

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

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

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

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

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

示例11: setUpClass

    def setUpClass(cls):
        super(LiveTestCase, cls).setUpClass()

        options = Options()
        options.headless = True

        cls.selenium = WebDriver(options=options)
        cls.selenium.implicitly_wait(10)
開發者ID:mbraak,項目名稱:django-mptt-admin,代碼行數:8,代碼來源:test_live.py

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

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

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

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


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