当前位置: 首页>>代码示例>>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;未经允许,请勿转载。