Python selenium.webdriver.firefox.options.Options() Examples

The following are 30 code examples of selenium.webdriver.firefox.options.Options(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module selenium.webdriver.firefox.options , or try the search function .
Example #1
Source File: test_examples.py    From python-anticaptcha with MIT License 10 votes vote down vote up
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() 
Example #2
Source File: spider_weixun_by_sogou.py    From WeixinSpider with Apache License 2.0 7 votes vote down vote up
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


# 获取公众号文章内容 
Example #3
Source File: browser_tools.py    From AdultScraperX-server with GNU General Public License v3.0 7 votes vote down vote up
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 
Example #4
Source File: driver_firefox.py    From whalesong with MIT License 7 votes vote down vote up
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 
Example #5
Source File: amazon_bot.py    From youtube_tutorials with GNU General Public License v3.0 6 votes vote down vote up
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') 
Example #6
Source File: kleinanzeigen.py    From ebayKleinanzeigen with Apache License 2.0 6 votes vote down vote up
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 
Example #7
Source File: utils.py    From opencraft with GNU Affero General Public License v3.0 6 votes vote down vote up
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) 
Example #8
Source File: test_iframe.py    From branca with MIT License 6 votes vote down vote up
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() 
Example #9
Source File: launcher.py    From kibitzr with MIT License 6 votes vote down vote up
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] 
Example #10
Source File: __init__.py    From diffengine with MIT License 6 votes vote down vote up
def geckodriver_browser():
    opts = FirefoxOptions()
    opts.headless = True
    return webdriver.Firefox(options=opts) 
Example #11
Source File: test_iframe.py    From branca with MIT License 5 votes vote down vote up
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 
Example #12
Source File: conftest.py    From pyodide with Mozilla Public License 2.0 5 votes vote down vote up
def get_driver(self):
        from selenium.webdriver import Firefox
        from selenium.webdriver.firefox.options import Options
        from selenium.common.exceptions import JavascriptException

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

        self.JavascriptException = JavascriptException

        return Firefox(executable_path="geckodriver", options=options) 
Example #13
Source File: conftest.py    From pyodide with Mozilla Public License 2.0 5 votes vote down vote up
def get_driver(self):
        from selenium.webdriver import Chrome
        from selenium.webdriver.chrome.options import Options
        from selenium.common.exceptions import WebDriverException

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

        self.JavascriptException = WebDriverException

        return Chrome(options=options) 
Example #14
Source File: conftest.py    From picasso with Eclipse Public License 1.0 5 votes vote down vote up
def webdriver():
    options = Options()
    options.add_argument('-headless')
    driver = Firefox(firefox_options=options)
    yield driver
    driver.quit() 
Example #15
Source File: utils.py    From redtide with MIT License 5 votes vote down vote up
def start_webdrive_instance(url, headless=True, exe=None, log_path='/dev/null'):
    o = Options()
    o.headless = headless
    if exe is None:
        driver = webdriver.Firefox(service_log_path=log_path, options=o)
    else:
        driver = webdriver.Firefox(executable_path=exe,
                                   service_log_path=log_path, options=o)
    driver.get(url)

    return driver 
Example #16
Source File: driver.py    From behave-webdriver with MIT License 5 votes vote down vote up
def headless(cls, *args, **kwargs):
        firefox_options = kwargs.pop('firefox_options', None)
        if firefox_options is None:
            firefox_options = FirefoxOptions()
        firefox_options.add_argument('--headless')
        kwargs['firefox_options'] = firefox_options
        return cls(*args, **kwargs) 
Example #17
Source File: test_frontend.py    From multiscanner with Mozilla Public License 2.0 5 votes vote down vote up
def setUp(self):
        """Set up test driver"""
        opts = Options()
        opts.add_argument('-headless')
        self.driver = webdriver.Firefox(firefox_options=opts)
        self.driver.get(self.get_server_url()) 
Example #18
Source File: check_numbers.py    From openprescribing with MIT License 5 votes vote down vote up
def handle(self, *args, **options):
        if import_in_progress():
            notify_slack("Not checking numbers: import in progress")
            return

        previous_log_path = get_previous_log_path()

        timestamp = datetime.now().strftime("%Y%m%d%H%M%S")
        log_path = os.path.join(settings.CHECK_NUMBERS_BASE_PATH, timestamp)
        mkdir_p(log_path)

        numbers = {}
        options = Options()
        options.headless = True
        with webdriver.Firefox(options=options) as browser:
            browser.set_page_load_timeout(60)

            for name, path in paths_to_scrape():
                source = get_page_source(browser, path, name, log_path)
                numbers_list = extract_numbers(source)
                numbers[name] = {"path": path, "numbers": numbers_list}

        write_numbers(numbers, log_path)

        if previous_log_path is None:
            msg = "Not checking numbers: this is the first deploy since last import"
            notify_slack(msg)
            return

        previous_numbers = load_previous_numbers(previous_log_path)

        differences = compare_numbers(previous_numbers, numbers)

        if differences:
            msg = "The following pages have changed:\n\n"
            msg += "\n".join(differences)
            msg += "\n\nNext step: compare {} and {}".format(
                previous_log_path, log_path
            )
            notify_slack(msg) 
Example #19
Source File: link_fetcher.py    From medium-crawler with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, driver_type='headless', username='nishparadox'):
        if not username:
            raise ValueError("Invalid username")
        self.username = username
        self.url = "https://medium.com/@{}/latest".format(username)
        self.driver_type = driver_type
        if driver_type == 'headless':
            options = Options()
            options.set_headless(headless=True)
            self.driver = webdriver.Firefox(firefox_options=options)
        elif driver_type == 'chrome':
            self.driver = webdriver.Chrome()
        else:
            self.driver = webdriver.Firefox() 
Example #20
Source File: test_web_backtest.py    From tqsdk-python with Apache License 2.0 5 votes vote down vote up
def setUp(self) -> None:
        self.ins = MockInsServer(5000)
        self.firefox_options = FirefoxOptions()
        self.firefox_options.headless = True
        ctx = mp.get_context('spawn')
        self.port = "8081"
        self.q = ctx.Queue()
        self.tq_process = ctx.Process(target=run_tianqin_code, args=(self.port, self.q))
        self.tq_process.start()
        self.q.get() 
Example #21
Source File: test_web.py    From tqsdk-python with Apache License 2.0 5 votes vote down vote up
def setUp(self) -> None:
        self.ins = MockInsServer(5000)
        self.firefox_options = FirefoxOptions()
        self.firefox_options.headless = True
        ctx = mp.get_context('spawn')
        self.port = "8083"
        self.q = ctx.Queue()
        self.tq_process = ctx.Process(target=run_tianqin_code, args=(self.port, self.q))
        self.tq_process.start()
        self.q.get() 
Example #22
Source File: __init__.py    From timestrap with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def setUpClass(cls):
        options = FirefoxOptions()
        if environ.get("MOZ_HEADLESS") != "0":
            # Setting environ var might seem redundant but some versions of firefox
            # and geckodriver fail to obey -headless properly
            environ["MOZ_HEADLESS"] = "1"
            options.add_argument("-headless")
        cls.driver = FirefoxDriver(firefox_options=options)
        cls.driver.maximize_window()
        cls.driver.implicitly_wait(2)
        cls.driver.set_page_load_timeout(30)

        super().setUpClass() 
Example #23
Source File: config_driver.py    From toolium with Apache License 2.0 5 votes vote down vote up
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) 
Example #24
Source File: affiliate_cookie_tests.py    From course-discovery with GNU Affero General Public License v3.0 5 votes vote down vote up
def setUp(self):
        super().setUp()
        opts = Options()
        opts.set_headless()
        self.browser = webdriver.Firefox(opts)
        self.cookie_name = AFFILIATE_COOKIE_NAME
        self.cookie_domain = COOKIE_DOMAIN 
Example #25
Source File: test_config_driver.py    From toolium with Apache License 2.0 5 votes vote down vote up
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 
Example #26
Source File: test_config_driver.py    From toolium with Apache License 2.0 5 votes vote down vote up
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'] 
Example #27
Source File: hsgtcg.py    From wanggeService with MIT License 5 votes vote down vote up
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 
Example #28
Source File: test_HSGTCGHold.py    From wanggeService with MIT License 5 votes vote down vote up
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() 
Example #29
Source File: lfs.py    From github-org-scripts with Mozilla Public License 2.0 5 votes vote down vote up
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() 
Example #30
Source File: browser.py    From QRLJacking with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self):
        self.opts = Options()
        self.opts.add_argument("--headless") # To make firefox invisible of course (Headless)
        self.browsers = {} # Here we save all the browsers we create so we can control and use later
        self.useragent = ""
        self.sessions_file = os.path.join("core","sessions.json")