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


Python options.Options方法代碼示例

本文整理匯總了Python中selenium.webdriver.firefox.options.Options方法的典型用法代碼示例。如果您正苦於以下問題:Python options.Options方法的具體用法?Python options.Options怎麽用?Python options.Options使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在selenium.webdriver.firefox.options的用法示例。


在下文中一共展示了options.Options方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_create_local_driver_firefox_binary

# 需要導入模塊: from selenium.webdriver.firefox import options [as 別名]
# 或者: from selenium.webdriver.firefox.options import Options [as 別名]
def test_create_local_driver_firefox_binary(webdriver_mock, config):
    config.set('Driver', 'type', 'firefox')
    config.add_section('Capabilities')
    config.set('Capabilities', 'marionette', 'false')
    config.add_section('Firefox')
    config.set('Firefox', 'binary', '/tmp/firefox')
    config_driver = ConfigDriver(config)
    config_driver._create_firefox_profile = lambda: 'firefox profile'
    DriverWrappersPool.output_directory = ''

    config_driver._create_local_driver()

    # Check that firefox options contain the firefox binary
    args, kwargs = webdriver_mock.Firefox.call_args
    firefox_options = kwargs['firefox_options']
    assert isinstance(firefox_options, Options)
    if isinstance(firefox_options.binary, str):
        assert firefox_options.binary == '/tmp/firefox'  # Selenium 2
    else:
        assert firefox_options.binary._start_cmd == '/tmp/firefox'  # Selenium 3 
開發者ID:Telefonica,項目名稱:toolium,代碼行數:22,代碼來源:test_config_driver.py

示例2: __init__

# 需要導入模塊: from selenium.webdriver.firefox import options [as 別名]
# 或者: from selenium.webdriver.firefox.options import Options [as 別名]
def __init__(self, items):
        """Setup bot for Amazon URL."""
        self.amazon_url = "https://www.amazon.ca/"
        self.items = items

        self.profile = webdriver.FirefoxProfile()
        self.options = Options()
        #self.options.add_argument("--headless")
        self.driver = webdriver.Firefox(firefox_profile=self.profile,
                                        firefox_options=self.options)

        # Navigate to the Amazon URL.
        self.driver.get(self.amazon_url)

        # Obtain the source
        self.html = self.driver.page_source
        self.soup = BeautifulSoup(self.html, 'html.parser')
        self.html = self.soup.prettify('utf-8') 
開發者ID:vprusso,項目名稱:youtube_tutorials,代碼行數:20,代碼來源:amazon_bot.py

示例3: setUp

# 需要導入模塊: from selenium.webdriver.firefox import options [as 別名]
# 或者: from selenium.webdriver.firefox.options import Options [as 別名]
def setUp(self):
        """
        Start firefox.
        """
        super().setUp()
        site = Site.objects.get()
        site.name = 'testing'
        site.domain = self.live_server_url.split('//')[1]
        site.save()
        options = Options()
        options.headless = True
        # Ensure we don't attempt to use the new geckodriver method (which
        # isn't working for us. I _think_ selenium 2 defaults to old method,
        # but just to make sure.
        cap = DesiredCapabilities().FIREFOX
        cap['marionette'] = False
        try:
            self.client = webdriver.Firefox(capabilities=cap, firefox_options=options)
        except WebDriverException:
            time.sleep(1)
            self.client = webdriver.Firefox(capabilities=cap, firefox_options=options) 
開發者ID:open-craft,項目名稱:opencraft,代碼行數:23,代碼來源:utils.py

示例4: firefox

# 需要導入模塊: from selenium.webdriver.firefox import options [as 別名]
# 或者: from selenium.webdriver.firefox.options import Options [as 別名]
def firefox(headless=True):
    """
    Context manager returning Selenium webdriver.
    Instance is reused and must be cleaned up on exit.
    """
    from selenium import webdriver
    from selenium.webdriver.firefox.options import Options
    if headless:
        driver_key = 'headless'
        firefox_options = Options()
        firefox_options.add_argument('-headless')
    else:
        driver_key = 'headed'
        firefox_options = None
    # Load profile, if it exists:
    if os.path.isdir(PROFILE_DIR):
        firefox_profile = webdriver.FirefoxProfile(PROFILE_DIR)
    else:
        firefox_profile = None
    if FIREFOX_INSTANCE[driver_key] is None:
        FIREFOX_INSTANCE[driver_key] = webdriver.Firefox(
            firefox_profile=firefox_profile,
            firefox_options=firefox_options,
        )
    yield FIREFOX_INSTANCE[driver_key] 
開發者ID:kibitzr,項目名稱:kibitzr,代碼行數:27,代碼來源:launcher.py

示例5: session_create

# 需要導入模塊: from selenium.webdriver.firefox import options [as 別名]
# 或者: from selenium.webdriver.firefox.options import Options [as 別名]
def session_create(config):
    log.info("Creating session")

    options = Options()
    if config.get('headless', False) is True:
        log.info("Headless mode")
        options.add_argument("--headless")

    if config.get('webdriver_enabled') is False:
        options.set_preference("dom.webdriver.enabled", False)
    
    driver = webdriver.Firefox(options=options)

    log.info("New session is: %s %s" % (driver.session_id, driver.command_executor._url))

    return driver 
開發者ID:donwayo,項目名稱:ebayKleinanzeigen,代碼行數:18,代碼來源:kleinanzeigen.py

示例6: test_process

# 需要導入模塊: from selenium.webdriver.firefox import options [as 別名]
# 或者: from selenium.webdriver.firefox.options import Options [as 別名]
def test_process(self):
        from examples import recaptcha_selenium
        from selenium.webdriver import Firefox
        from selenium.webdriver.firefox.options import Options
        from selenium.webdriver import FirefoxProfile

        options = Options()
        options.add_argument("-headless")

        ffprofile = FirefoxProfile()
        ffprofile.set_preference("intl.accept_languages", "en-US")

        driver = Firefox(firefox_profile=ffprofile, firefox_options=options)
        self.assertIn(
            recaptcha_selenium.EXPECTED_RESULT, recaptcha_selenium.process(driver)
        )
        driver.quit() 
開發者ID:ad-m,項目名稱:python-anticaptcha,代碼行數:19,代碼來源:test_examples.py

示例7: getBrowser

# 需要導入模塊: from selenium.webdriver.firefox import options [as 別名]
# 或者: from selenium.webdriver.firefox.options import Options [as 別名]
def getBrowser(self):

        if config.BROWSER_DRIVE is 'firefox':
            from selenium.webdriver.firefox.options import Options
            firefox_opt = Options()
            firefox_opt.headless = True
            self.browser = webdriver.Firefox(options=firefox_opt)
        if config.BROWSER_DRIVE is 'chrome':
            chrome_options = webdriver.ChromeOptions()
            chrome_options.add_argument('--no-sandbox')
            chrome_options.add_argument('--headless')
            chrome_options.add_argument('--disable-setuid-sandbox')
            chrome_options.add_argument('--disable-dev-shm-usage')
            chrome_options.add_argument('--disable-gpu')
            self.browser = webdriver.Chrome(chrome_options=chrome_options)

        return self.browser 
開發者ID:AdultScraperX,項目名稱:AdultScraperX-server,代碼行數:19,代碼來源:browser_tools.py

示例8: _internal_start_driver_sync

# 需要導入模塊: from selenium.webdriver.firefox import options [as 別名]
# 或者: from selenium.webdriver.firefox.options import Options [as 別名]
def _internal_start_driver_sync(self):
        capabilities = DesiredCapabilities.FIREFOX.copy()
        capabilities['webStorageEnabled'] = True
        capabilities['databaseEnabled'] = True

        self.logger.info("Starting webdriver")
        options = Options()

        if self.options['headless']:
            options.headless = True

        self._marionette_port = self.free_port()
        self._profile.set_preference('marionette.port', self._marionette_port)
        self._profile.update_preferences()
        options.add_argument('-profile')
        options.add_argument(self._profile.profile_dir)

        driver = webdriver.Firefox(capabilities=capabilities,
                                   options=options,
                                   service_args=['--marionette-port', str(self._marionette_port)],
                                   **self.options['extra_params'])

        driver.set_script_timeout(500)
        driver.implicitly_wait(10)
        return driver 
開發者ID:alfred82santa,項目名稱:whalesong,代碼行數:27,代碼來源:driver_firefox.py

示例9: test_rendering_figure_notebook

# 需要導入模塊: from selenium.webdriver.firefox import options [as 別名]
# 或者: from selenium.webdriver.firefox.options import Options [as 別名]
def test_rendering_figure_notebook():
    """Verify special characters are correctly rendered in Jupyter notebooks."""
    text = '5/7 %, Линейная улица, "\u00e9 Berdsk"'
    figure = elem.Figure()
    elem.Html(text).add_to(figure.html)
    html = figure._repr_html_()

    filepath = 'temp_test_rendering_figure_notebook.html'
    filepath = os.path.abspath(filepath)
    with open(filepath, 'w') as f:
        f.write(html)

    options = Options()
    options.add_argument('-headless')
    driver = Firefox(options=options)
    try:
        driver.get('file://' + filepath)
        driver.switch_to.frame(0)
        text_div = driver.find_element_by_css_selector('div')
        assert text_div.text == text
    finally:
        os.remove(filepath)
        driver.quit() 
開發者ID:python-visualization,項目名稱:branca,代碼行數:25,代碼來源:test_iframe.py

示例10: get_selenium_js_html

# 需要導入模塊: from selenium.webdriver.firefox import options [as 別名]
# 或者: from selenium.webdriver.firefox.options import Options [as 別名]
def get_selenium_js_html(url):
    # browser = webdriver.PhantomJS(executable_path=r'D:\Python2.7\Scripts\phantomjs.exe')
    options = Options()
    options.add_argument('-headless')  # 無頭參數
    driver = Chrome(executable_path='chromedriver', chrome_options=options)
    wait = WebDriverWait(driver, timeout=10)

    driver.get(url)
    time.sleep(3)
    # 執行js得到整個頁麵內容
    html = driver.execute_script("return document.documentElement.outerHTML")
    driver.close()
    return html


# 獲取公眾號文章內容 
開發者ID:feiweiwei,項目名稱:WeixinSpider,代碼行數:18,代碼來源:spider_weixun_by_sogou.py

示例11: _setup_firefox

# 需要導入模塊: from selenium.webdriver.firefox import options [as 別名]
# 或者: from selenium.webdriver.firefox.options import Options [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:Telefonica,項目名稱:toolium,代碼行數:37,代碼來源:config_driver.py

示例12: test_add_firefox_arguments

# 需要導入模塊: from selenium.webdriver.firefox import options [as 別名]
# 或者: from selenium.webdriver.firefox.options import Options [as 別名]
def test_add_firefox_arguments(config):
    config.add_section('FirefoxArguments')
    config.set('FirefoxArguments', '-private', '')
    config_driver = ConfigDriver(config)
    firefox_options = Options()

    config_driver._add_firefox_arguments(firefox_options)
    assert firefox_options.arguments == ['-private'] 
開發者ID:Telefonica,項目名稱:toolium,代碼行數:10,代碼來源:test_config_driver.py

示例13: getBrowser

# 需要導入模塊: from selenium.webdriver.firefox import options [as 別名]
# 或者: from selenium.webdriver.firefox.options import Options [as 別名]
def getBrowser(headless=None, proxies=False, pageloadtimeout=25):
        """ 獲取webdriver瀏覽器

        :param headless: 是否無窗口模式
        :param pageloadtimeout: 加載頁麵超時(秒)
        :return: browser
        """
        opts = Options()
        if headless:
            opts.set_headless()
            # opts.add_argument('-headless')

        # browser = webdriver.Firefox()

        if proxies:
            from selenium.webdriver.common.proxy import Proxy, ProxyType
            global myProxy
            myProxy = mProxy.getNextProxy()
            desired_capability = webdriver.DesiredCapabilities.FIREFOX
            desired_capability['proxy'] = {
                "proxyType": "manual",
                "httpProxy": myProxy,
                "ftpProxy": myProxy,
                "sslProxy": myProxy
            }
            browser = webdriver.Firefox(firefox_options=opts, capabilities=desired_capability)
        else:
            browser = webdriver.Firefox(firefox_options=opts)
        # assert opts.headless  # operating in headless mode
        browser.set_page_load_timeout(pageloadtimeout)
        if not headless:
            browser.maximize_window()
        return browser 
開發者ID:pchaos,項目名稱:wanggeService,代碼行數:35,代碼來源:hsgtcg.py

示例14: test_chromewebdriver

# 需要導入模塊: from selenium.webdriver.firefox import options [as 別名]
# 或者: from selenium.webdriver.firefox.options import Options [as 別名]
def test_chromewebdriver(self):
        """ 測試 webdriver chrome
        chrome比firefox快一點

        :return:
        """
        from selenium.webdriver.chrome.options import Options

        # CHROME_PATH = '/usr/bin/google-chrome'
        WINDOW_SIZE = "1920,1080"

        chrome_options = Options()
        chrome_options.add_argument("--headless")
        chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE)
        # chrome_options.binary_location = CHROME_PATH

        browser = webdriver.Chrome(chrome_options=chrome_options)
        try:
            url = 'http://data.eastmoney.com/hsgtcg/StockStatistics.aspx'
            browser.get(url)
            # 北向持股
            browser.find_element_by_css_selector('.border_left_1').click()
            time.sleep(0.2)
            # 自定義區間
            browser.find_element_by_css_selector('.custom-text > span:nth-child(1)').click()
            time.sleep(0.5)
            # 開始日期賦值
            tdate = browser.find_element_by_css_selector('input.date-input:nth-child(1)')
            tdate.send_keys(str(datetime.datetime.now().date()-datetime.timedelta(10)))
            time.sleep(0.5)
            tdate = browser.find_element_by_css_selector('.search-btn')
            time.sleep(5)

        finally:
            if browser:
                browser.close() 
開發者ID:pchaos,項目名稱:wanggeService,代碼行數:38,代碼來源:test_HSGTCGHold.py

示例15: main

# 需要導入模塊: from selenium.webdriver.firefox import options [as 別名]
# 或者: from selenium.webdriver.firefox.options import Options [as 別名]
def main():
    args = parse_args()
    print("Obtain current LFS billing info")
    print("Attempting login as '{}', please enter OTP when asked".format(GH_LOGIN))
    print("  (if wrong, set GH_LOGIN & GH_PASSWORD in environtment properly)")
    quit = not args.debug
    try:
        # hack to allow script reload in iPython without destroying
        # exisiting instance
        driver
    except NameError:
        driver = None
    if not driver:
        from selenium.webdriver.firefox.options import Options

        opts = Options()
        opts.log.level = "trace"
        try:
            token = input("token please: ")
            driver = LFS_Usage(headless=args.headless, options=opts)
            driver.login(GH_LOGIN, GH_PASSWORD, URL, "Billing", token)
            results = driver.get_usage()
            results["time"] = time.strftime("%Y-%m-%d %H:%M")
            print(json.dumps(results))
        except WebDriverException:
            quit = not args.debug
            print("Deep error - did browser crash?")
        except ValueError as e:
            quit = not args.debug
            print("Navigation issue: {}".format(e.args[0]))

        if quit:
            driver.quit()
        else:
            import pdb

            pdb.set_trace() 
開發者ID:mozilla,項目名稱:github-org-scripts,代碼行數:39,代碼來源:lfs.py


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