Python selenium.webdriver.ChromeOptions() Examples

The following are 30 code examples of selenium.webdriver.ChromeOptions(). 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 , or try the search function .
Example #1
Source File: views.py    From MPContribs with MIT License 29 votes vote down vote up
def get_browser():
    if "browser" not in g:
        options = webdriver.ChromeOptions()
        options.add_argument("no-sandbox")
        options.add_argument("--disable-gpu")
        options.add_argument("--window-size=800,600")
        options.add_argument("--disable-dev-shm-usage")
        options.set_headless()
        host = "chrome" if current_app.config["DEBUG"] else "127.0.0.1"
        g.browser = webdriver.Remote(
            command_executor=f"http://{host}:4444/wd/hub",
            desired_capabilities=DesiredCapabilities.CHROME,
            options=options,
        )
    return g.browser 
Example #2
Source File: ipip.py    From scripts with MIT License 16 votes vote down vote up
def create_driver():
    option = webdriver.ChromeOptions()
    option.add_argument("--headless")
    option.add_argument("--host-resolver-rules=MAP www.google-analytics.com 127.0.0.1")
    option.add_argument('user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36')
    return webdriver.Chrome(options=option) 
Example #3
Source File: util.py    From NoXss with MIT License 16 votes vote down vote up
def chrome(headless=False):
    # support to get response status and headers
    d = DesiredCapabilities.CHROME
    d['loggingPrefs'] = {'performance': 'ALL'}
    opt = webdriver.ChromeOptions()
    if headless:
        opt.add_argument("--headless")
    opt.add_argument("--disable-xss-auditor")
    opt.add_argument("--disable-web-security")
    opt.add_argument("--allow-running-insecure-content")
    opt.add_argument("--no-sandbox")
    opt.add_argument("--disable-setuid-sandbox")
    opt.add_argument("--disable-webgl")
    opt.add_argument("--disable-popup-blocking")
    # prefs = {"profile.managed_default_content_settings.images": 2,
    #          'notifications': 2,
    #          }
    # opt.add_experimental_option("prefs", prefs)
    browser = webdriver.Chrome(options=opt,desired_capabilities=d)
    browser.implicitly_wait(10)
    browser.set_page_load_timeout(20)
    return browser 
Example #4
Source File: send_card.py    From ankigenbot with GNU General Public License v3.0 11 votes vote down vote up
def __init__(self, username, password):
        self.driver = None

        self.last_access = time.time()

        options = webdriver.ChromeOptions()
        options.add_argument("--window-size=1920x1080")
        options.add_argument('--ignore-certificate-errors')
        options.add_argument('--headless')
        options.add_argument('--no-sandbox')
        options.add_argument('--disable-dev-shm-usage')

        options.binary_location = "/usr/lib/chromium-browser/chromium-browser"
        self.driver = webdriver.Chrome(chrome_options=options)

        self.driver.set_window_size(1920, 1080)
        self.driver.get(CardSender.url)
        usr_box = self.driver.find_element_by_id('email')
        usr_box.send_keys(username)
        pass_box = self.driver.find_element_by_id('password')
        pass_box.send_keys('{}\n'.format(password)) 
Example #5
Source File: locusts.py    From realbrowserlocusts with MIT License 9 votes vote down vote up
def __init__(self):
        super(HeadlessChromeLocust, self).__init__()
        options = webdriver.ChromeOptions()
        options.add_argument('headless')
        options.add_argument('window-size={}x{}'.format(
            self.screen_width, self.screen_height
        ))
        options.add_argument('disable-gpu')
        if self.proxy_server:
            _LOGGER.info('Using proxy: ' + self.proxy_server)
            options.add_argument('proxy-server={}'.format(self.proxy_server))
        driver = webdriver.Chrome(chrome_options=options)
        _LOGGER.info('Actually trying to run headless Chrome')
        self.client = RealBrowserClient(
            driver,
            self.timeout,
            self.screen_width,
            self.screen_height,
            set_window=False
        ) 
Example #6
Source File: fixtures.py    From wagtail-tag-manager with BSD 3-Clause "New" or "Revised" License 8 votes vote down vote up
def driver():
    options = webdriver.ChromeOptions()
    options.add_argument("disable-gpu")
    options.add_argument("headless")
    options.add_argument("no-default-browser-check")
    options.add_argument("no-first-run")
    options.add_argument("no-sandbox")

    d = DesiredCapabilities.CHROME
    d["loggingPrefs"] = {"browser": "ALL"}

    driver = webdriver.Chrome(options=options, desired_capabilities=d)
    driver.implicitly_wait(30)

    yield driver
    driver.quit() 
Example #7
Source File: custom_driver.py    From king-bot with MIT License 8 votes vote down vote up
def headless(self, path: str, proxy: str = "") -> None:
        ua = UserAgent()
        userAgent = ua.random
        options = webdriver.ChromeOptions()
        options.add_argument("headless")
        options.add_argument("window-size=1500,1200")
        options.add_argument("no-sandbox")
        options.add_argument("disable-dev-shm-usage")
        options.add_argument("disable-gpu")
        options.add_argument("log-level=3")
        options.add_argument(f"user-agent={userAgent}")

        if proxy != "":
            self.proxy = True
            options.add_argument("proxy-server={}".format(proxy))

        self.driver = webdriver.Chrome(path, chrome_options=options)
        self.set_config()
        self._headless = True 
Example #8
Source File: rasterize.py    From content with MIT License 6 votes vote down vote up
def init_driver(offline_mode=False):
    """
    Creates headless Google Chrome Web Driver
    """
    demisto.debug(f'Creating chrome driver. Mode: {"OFFLINE" if offline_mode else "ONLINE"}')
    try:
        chrome_options = webdriver.ChromeOptions()
        for opt in merge_options(DEFAULT_CHROME_OPTIONS, USER_CHROME_OPTIONS):
            chrome_options.add_argument(opt)
        driver = webdriver.Chrome(options=chrome_options, service_args=[
            f'--log-path={DRIVER_LOG}',
        ])
        if offline_mode:
            driver.set_network_conditions(offline=True, latency=5, throughput=500 * 1024)
    except Exception as ex:
        return_error(f'Unexpected exception: {ex}\nTrace:{traceback.format_exc()}')

    demisto.debug('Creating chrome driver - COMPLETED')
    return driver 
Example #9
Source File: selenium_chrome_http_auth.py    From python-sdk with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def get_chromedriver(use_proxy=False, user_agent=None):
    # path = os.path.dirname(os.path.abspath(__file__)) # 如果没有把chromedriver放到python\script\下,则需要指定路径
    chrome_options = webdriver.ChromeOptions()
    if use_proxy:
        pluginfile = 'proxy_auth_plugin.zip'

        with zipfile.ZipFile(pluginfile, 'w') as zp:
            zp.writestr("manifest.json", manifest_json)
            zp.writestr("background.js", background_js)
        chrome_options.add_extension(pluginfile)
    if user_agent:
        chrome_options.add_argument('--user-agent=%s' % user_agent)
    driver = webdriver.Chrome(
        # os.path.join(path, 'chromedriver'),
        chrome_options=chrome_options)
    return driver 
Example #10
Source File: power_views.py    From Python-tools with MIT License 6 votes vote down vote up
def get_page(url):
    chrome_options = webdriver.ChromeOptions()
    ua_argument = 'User-Agent="'+GetUserAgent()+'"'
    chrome_options.add_argument(ua_argument)
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-gpu')
    chrome_options.add_argument('--incognito')
    chrome_options.add_argument('log-level=3')
    try:
        driver = webdriver.Chrome(chrome_options=chrome_options)
        #driver.set_page_load_timeout(6)
        # driver.set_script_timeout(6)
        driver.get(url)
        # time.sleep(0.5)
        driver.quit()
    except:
        driver.quit()
        print("timeout") 
Example #11
Source File: config_driver.py    From toolium with Apache License 2.0 6 votes vote down vote up
def _create_chrome_options(self):
        """Create and configure a chrome options object

        :returns: chrome options object
        """
        # Get Chrome binary
        chrome_binary = self.config.get_optional('Chrome', 'binary')

        # Create Chrome options
        options = webdriver.ChromeOptions()

        if self.config.getboolean_optional('Driver', 'headless'):
            self.logger.debug("Running Chrome in headless mode")
            options.add_argument('--headless')
            if os.name == 'nt':  # Temporarily needed if running on Windows.
                options.add_argument('--disable-gpu')

        if chrome_binary is not None:
            options.binary_location = chrome_binary

        # Add Chrome preferences, mobile emulation options and chrome arguments
        self._add_chrome_options(options, 'prefs')
        self._add_chrome_options(options, 'mobileEmulation')
        self._add_chrome_arguments(options)

        return options 
Example #12
Source File: WebDriver.py    From Delete-my-hisroy-in-tieba with GNU General Public License v3.0 5 votes vote down vote up
def Start_with_Chrome_without_images():
    chrome_options = webdriver.ChromeOptions()
    prefs = {
        "profile.managed_default_content_settings.images": 2
    }
    chrome_options.add_experimental_option("prefs", prefs)
    driver = webdriver.Chrome(chrome_options=chrome_options)
    return driver 
Example #13
Source File: ip_pool_browse.py    From Python-tools with MIT License 5 votes vote down vote up
def auto_open(url,ip_port):
    chrome_options = webdriver.ChromeOptions()
    usr_agents = GetUserAgent()
    proxy_argument = "--proxy-server=http://" + ip_port
    ua_argument = 'User-Agent="'+usr_agents+'"'
    chrome_options.add_argument(proxy_argument)
    chrome_options.add_argument(ua_argument)
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-gpu')
    chrome_options.add_argument('log-level=3')
    try:
        driver = webdriver.Chrome(chrome_options=chrome_options)
        # driver.set_page_load_timeout(6)
        # driver.set_script_timeout(6)
        driver.get(url)
        # time.sleep(0.5)
        a = driver.page_source
        if re.search("ERR_PROXY_CONNECTION_FAILED",a):
            print("connection error:{}".format(ip_port))
            driver.quit()
            return False
        else:
            print("200 OK")
            driver.quit()
            return True
    except:
        # time.sleep(3)
        driver.quit()
        print("timeout:{}".format(ip_port))
        return False 
Example #14
Source File: web.py    From automation-for-humans with MIT License 5 votes vote down vote up
def init_driver(program, arguments):
    # Initialise the options.
    options = webdriver.ChromeOptions()
    options.add_argument("--start-maximized")
    options.add_argument("--no-sandbox")
    options.add_argument("--disable-dev-shm-usage")

    if config["run-headless"]:
        options.add_argument("--headless")
    # Initialise the driver.
    driver = webdriver.Chrome(chrome_options=options)
    driver.set_window_size(config["window-width"], config["window-height"])

    return driver 
Example #15
Source File: tmall_crawler.py    From examples-of-web-crawlers with MIT License 5 votes vote down vote up
def __init__(self):
        url = 'https://login.taobao.com/member/login.jhtml'
        self.url = url

        options = webdriver.ChromeOptions()
        options.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2}) # 不加载图片,加快访问速度
        options.add_experimental_option('excludeSwitches', ['enable-automation']) # 此步骤很重要,设置为开发者模式,防止被各大网站识别出来使用了Selenium

        self.browser = webdriver.Chrome(executable_path=chromedriver_path, options=options)
        self.wait = WebDriverWait(self.browser, 10) #超时时长为10s


    #延时操作,并可选择是否弹出窗口提示 
Example #16
Source File: environment.py    From intake with MIT License 5 votes vote down vote up
def before_all(context):
    # start_local()
    desired_cap = {
        'browser': 'Chrome',
        'browser_version': '57.0',
        'os': 'Windows',
        'os_version': '7',
        'resolution': '1024x768',
    }
    desired_capabilities = desired_cap
    desired_capabilities['browserstack.local'] = True
    desired_capabilities['browserstack.debug'] = True
    # url = 'http://%s:%s@hub.browserstack.com:80/wd/hub'
    # context.browser = webdriver.Remote(
    #     desired_capabilities=desired_capabilities,
    #     command_executor=url % (USERNAME, ACCESS_KEY)
    # )
    options = webdriver.ChromeOptions()
    options.add_argument('headless')

    # fixes weird chrome keychain popup, as described here:
    # https://groups.google.com/d/msg/chromedriver-users/ktp-s_0M5NM/lFerFJSlAgAJ
    options.add_argument("enable-features=NetworkService,NetworkServiceInProcess")

    context.browser = webdriver.Chrome(chrome_options=options)
    context.browser.implicitly_wait(10)
    settings.DIVERT_REMOTE_CONNECTIONS = True
    setup_debug_on_error(context.config.userdata) 
Example #17
Source File: testAll.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def setUp(self):
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('headless')
        chrome_options.add_argument('window-size=1920x1080')
        self.driver = webdriver.Chrome(options=chrome_options) 
Example #18
Source File: testAll.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def setUp(self):
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('headless')
        chrome_options.add_argument('window-size=1920x1080')
        self.driver = webdriver.Chrome(options=chrome_options) 
Example #19
Source File: pdf_problems.py    From online-judge with GNU Affero General Public License v3.0 5 votes vote down vote up
def _make(self, debug):
        options = webdriver.ChromeOptions()
        options.add_argument("--headless")
        options.binary_location = settings.SELENIUM_CUSTOM_CHROME_PATH

        browser = webdriver.Chrome(settings.SELENIUM_CHROMEDRIVER_PATH, options=options)
        browser.get('file://' + os.path.abspath(os.path.join(self.dir, 'input.html')))
        self.log = self.get_log(browser)

        try:
            WebDriverWait(browser, 15).until(EC.presence_of_element_located((By.CLASS_NAME, 'math-loaded')))
        except TimeoutException:
            logger.error('PDF math rendering timed out')
            self.log = self.get_log(browser) + '\nPDF math rendering timed out'
            return

        response = browser.execute_cdp_cmd('Page.printToPDF', self.template)
        self.log = self.get_log(browser)
        if not response:
            return

        with open(os.path.abspath(os.path.join(self.dir, 'output.pdf')), 'wb') as f:
            f.write(base64.b64decode(response['data']))

        self.success = True 
Example #20
Source File: fridolin.py    From ad-versarial with MIT License 5 votes vote down vote up
def build_driver(use_adb=False, proxy=None, lang=None, timeout=MAX_TIMEOUT, fullscreen=True):
    opts = webdriver.ChromeOptions()

    #opts.add_argument("load-extension=../misc/jsinj/")

    if use_adb:
        opts.add_argument("load-extension=../misc/adblocker/unpacked/3.21.0_0/")

    if proxy:
        opts.add_argument("proxy-server={}".format(proxy))

    #opts.add_argument("start-maximized")
    if fullscreen:
        opts.add_argument("start-fullscreen")

    opts.add_argument("disable-infobars") # we remove the ugly yellow notification "Chrome is being controlled by automated test software"
    #opts.add_argument("disable-web-security") # We need this to disable SOP and access iframe content

    if lang:
        #print lang
        opts.add_argument("lang={}".format(lang))

    driver = webdriver.Chrome(executable_path="/usr/lib/chromium-browser/chromedriver", chrome_options=opts)

    if timeout:
        driver.set_page_load_timeout(timeout)

    return driver 
Example #21
Source File: testAll.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def setUp(self):
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('headless')
        chrome_options.add_argument('window-size=1920x1080')
        self.driver = webdriver.Chrome(options=chrome_options) 
Example #22
Source File: scraping.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def sel(url):
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('headless')
    chrome_options.add_argument('window-size=1920x1080')
    driver = webdriver.Chrome(options=chrome_options)
    driver.get(url)
    event_list = driver.find_element_by_css_selector('#content ul[class="list-recent-events menu"]')
    return BeautifulSoup(event_list.get_attribute('innerHTML'), 'html.parser') 
Example #23
Source File: testAllChrome.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def setUp(self):
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('headless')
        chrome_options.add_argument('window-size=1920x1080')
        self.driver = webdriver.Chrome(options=chrome_options) 
Example #24
Source File: testAll.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def setUp(self):
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('headless')
        chrome_options.add_argument('window-size=1920x1080')
        self.driver = webdriver.Chrome(options=chrome_options) 
Example #25
Source File: testAll.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def setUp(self):
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('headless')
        chrome_options.add_argument('window-size=1920x1080')
        self.driver = webdriver.Chrome(options=chrome_options) 
Example #26
Source File: testAll.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def setUp(self):
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('headless')
        chrome_options.add_argument('window-size=1920x1080')
        self.driver = webdriver.Chrome(options=chrome_options) 
Example #27
Source File: testAll.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def setUp(self):
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('headless')
        chrome_options.add_argument('window-size=1920x1080')
        self.driver = webdriver.Chrome(options=chrome_options) 
Example #28
Source File: testAll2.py    From -Automating-Web-Testing-with-Selenium-and-Python with MIT License 5 votes vote down vote up
def setUpClass(cls):
        chrome_options = webdriver.ChromeOptions()
        chrome_options.add_argument('headless')
        chrome_options.add_argument('window-size=1920x1080')
        cls.driver = webdriver.Chrome(options=chrome_options) 
Example #29
Source File: conftest.py    From vue.py with MIT License 5 votes vote down vote up
def __enter__(self):
        options = webdriver.ChromeOptions()
        options.add_argument("headless")
        options.add_argument("disable-gpu")
        options.add_argument("disable-dev-shm-usage")
        options.add_argument("no-sandbox")

        desired = DesiredCapabilities.CHROME
        desired["goog:loggingPrefs"] = {"browser": "ALL"}

        self.driver = webdriver.Chrome(
            CHROME_DRIVER_PATH, options=options, desired_capabilities=desired
        )
        return self 
Example #30
Source File: MyBrowser.py    From SAIVS with Apache License 2.0 5 votes vote down vote up
def __init__(self):
        # ブラウザの定義
        # obj_options = webdriver.ChromeOptions()
        # obj_options.add_argument('--disable-javascript')
        # self.obj_browser = webdriver.Chrome(executable_path=r".\\chromedriver_win32\\chromedriver.exe", chrome_options=obj_options)
        self.obj_browser = webdriver.Chrome(executable_path=r".\\chromedriver_win32\\chromedriver.exe")

        # 受信したレスポンスを出力するファイルパス
        self.str_html_file_path = os.path.join('.\\result', 'response.html')

    # 初回ブラウザ起動