当前位置: 首页>>代码示例>>Python>>正文


Python Options.headless方法代码示例

本文整理汇总了Python中selenium.webdriver.firefox.options.Options.headless方法的典型用法代码示例。如果您正苦于以下问题:Python Options.headless方法的具体用法?Python Options.headless怎么用?Python Options.headless使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在selenium.webdriver.firefox.options.Options的用法示例。


在下文中一共展示了Options.headless方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUpClass

# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import headless [as 别名]
    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,代码行数:10,代码来源:test_live.py

示例2: get_firefox_headless

# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import headless [as 别名]
def get_firefox_headless():
    # https://selenium-python.readthedocs.io/faq.html#how-to-auto-save-files-using-custom-firefox-profile
    fp = webdriver.FirefoxProfile()
    content_types = "text/plain,text/csv,application/csv,application/pdf"
    fp.set_preference("browser.download.folderList", 2)
    fp.set_preference("browser.download.manager.showWhenStarting", False)
    fp.set_preference("browser.download.dir", datadir)
    fp.set_preference("browser.helperApps.neverAsk.saveToDisk", content_types)
    fp.set_preference("browser.helperApps.neverAsk.openFile", content_types)
    fp.set_preference("plugin.scan.plid.all", False)
    fp.set_preference("plugin.scan.Acrobat", "99.0")
    fp.set_preference("pdfjs.disabled", True)
    options = Options()
    options.headless = True
    # options.log.level = "trace"
    driver = webdriver.Firefox(
        options=options,
        firefox_profile=fp,
        executable_path="/usr/local/bin/geckodriver",
        service_log_path=os.path.devnull,
        # service_log_path="/code/firefox.log",
    )
    return driver
开发者ID:captnswing,项目名称:banking,代码行数:25,代码来源:util.py

示例3: buy_ticket

# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import headless [as 别名]
def buy_ticket(args):

    # FIREFOX DESTINATION FOLDER
    folder = os.path.dirname(os.path.realpath(__file__))

    # FIREFOX OPTIONS
    options = Options();
    options.headless = args.headless

    # FIREFOX PROFILE
    profile = FirefoxProfile()
    profile.set_preference('browser.download.folderList',2);
    profile.set_preference('browser.download.manager.showWhenStarting', False);
    profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream,application/vnd.ms-excel');
    profile.set_preference('browser.download.dir',str(folder));
    log_info('FirefoxProfile: "browser.download.dir" = "{}"'.format(str(folder)))

    # Launch Firefox web browser.
    driver = webdriver.Firefox(options=options, firefox_profile=profile)

    # Use full screen mode.
    # driver.maximize_window()

    # Logging information
    log_info('Opened {} (version {})'.format(
            driver.capabilities['browserName'],
            driver.capabilities['browserVersion']
        )
    )

    # Sets a sticky timeout to implicitly wait for an element to be found, or a command to complete.
    driver.implicitly_wait(30)

    # Load page 'Vyhľadanie spojenia'
    driver.get('https://ikvc.slovakrail.sk/esales/search')

    # Info
    log_info('Loading page "Vyhľadanie spojenia"')

    try:
        delay = 30  # wait seconds for web page to load, added more second

        WebDriverWait(driver, delay).until(
            EC.presence_of_all_elements_located(
                (By.ID, 'searchPanel')
            )
        )

        # Logging information
        log_info('Loaded page "Vyhľadanie spojenia"')

    except TimeoutException:
        log_info('Loading took too much time.')
        log_info('Closed {} (version {}).'.format(
               driver.capabilities['browserName'],
               driver.capabilities['browserVersion']
           )
        )
        driver.close()
        die('Page loading failure.',1)

    sleep(1)

    # Info
    log_info('Page title is "{}".'.format(driver.title))

    # Check if 'ZSSK' is in the page title
    assert 'ZSSK' in driver.title

    # FROM
    elem_city_from = driver.find_element_by_id('fromInput')
    elem_city_from.clear()
    elem_city_from.send_keys(args.departure)
    driver.find_element_by_xpath(
        '/html/body/div[1]/div/div[2]/div[3]/div/div/form/div[1]/div/div[1]/div[1]/div[1]/ul/li/a'
    ).click
    log_info('Filling "Odkiaľ" in "Vyhľadanie spojenia" with "{}".'.format(args.departure))
    sleep(0.5)

    # TO
    elem_city_to = driver.find_element_by_id('toInput')
    elem_city_to.clear()
    elem_city_to.send_keys(args.arrival)
    driver.find_element_by_xpath(
        '/html/body/div[1]/div/div[2]/div[3]/div/div/form/div[1]/div/div[1]/div[1]/div[3]/ul/li/a'
    ).click
    log_info('Filling "Kam" in "Vyhľadanie spojenia" with "{}".'.format(args.arrival))
    sleep(0.5)

    # DATE
    elem_date = driver.find_element_by_id('departDate')
    elem_date.clear()
    elem_date.send_keys(args.date)
    driver.find_element_by_xpath('//html').click();
    log_info('Filling "Dátum cesty tam" in "Vyhľadanie spojenia" with "{}".'.format(args.date))
    sleep(0.5)

    # TIME
    elem_time = driver.find_element_by_id('departTime')
    elem_time.clear()
#.........这里部分代码省略.........
开发者ID:astaruch,项目名称:slovakrail-ticket-script,代码行数:103,代码来源:buy_ticket.py

示例4: _local_browser_class

# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import headless [as 别名]
def _local_browser_class(browser_name):
    """
    Returns class, kwargs, and args needed to instantiate the local browser.
    """

    # Log name of local browser
    LOGGER.info(u"Using local browser: %s [Default is firefox]", browser_name)

    # Get class of local browser based on name
    browser_class = BROWSERS.get(browser_name)
    headless = os.environ.get('BOKCHOY_HEADLESS', 'false').lower() == 'true'
    if browser_class is None:
        raise BrowserConfigError(
            u"Invalid browser name {name}.  Options are: {options}".format(
                name=browser_name, options=", ".join(list(BROWSERS.keys()))))
    else:
        if browser_name == 'firefox':
            # Remove geckodriver log data from previous test cases
            log_path = os.path.join(os.getcwd(), 'geckodriver.log')
            if os.path.exists(log_path):
                os.remove(log_path)

            firefox_options = FirefoxOptions()
            firefox_options.log.level = 'trace'
            if headless:
                firefox_options.headless = True
            browser_args = []
            browser_kwargs = {
                'firefox_profile': _firefox_profile(),
                'options': firefox_options,
            }

            firefox_path = os.environ.get('SELENIUM_FIREFOX_PATH')
            firefox_log = os.environ.get('SELENIUM_FIREFOX_LOG')
            if firefox_path and firefox_log:
                browser_kwargs.update({
                    'firefox_binary': FirefoxBinary(
                        firefox_path=firefox_path, log_file=firefox_log)
                })
            elif firefox_path:
                browser_kwargs.update({
                    'firefox_binary': FirefoxBinary(firefox_path=firefox_path)
                })
            elif firefox_log:
                browser_kwargs.update({
                    'firefox_binary': FirefoxBinary(log_file=firefox_log)
                })

        elif browser_name == 'chrome':
            chrome_options = ChromeOptions()
            if headless:
                chrome_options.headless = True

            # Emulate webcam and microphone for testing purposes
            chrome_options.add_argument('--use-fake-device-for-media-stream')

            # Bypasses the security prompt displayed by the browser when it attempts to
            # access a media device (e.g., a webcam)
            chrome_options.add_argument('--use-fake-ui-for-media-stream')

            browser_args = []
            browser_kwargs = {
                'options': chrome_options,
            }
        else:
            browser_args, browser_kwargs = [], {}

        return browser_class, browser_args, browser_kwargs
开发者ID:edx,项目名称:bok-choy,代码行数:70,代码来源:browser.py

示例5: setUp

# 需要导入模块: from selenium.webdriver.firefox.options import Options [as 别名]
# 或者: from selenium.webdriver.firefox.options.Options import headless [as 别名]
 def setUp(self):
     options = Options()
     options.headless = True
     self.driver = Firefox(options=options)
开发者ID:benmurden,项目名称:django-intl-tel-input,代码行数:6,代码来源:tests.py


注:本文中的selenium.webdriver.firefox.options.Options.headless方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。