Python selenium.webdriver.common.desired_capabilities.DesiredCapabilities.CHROME Examples

The following are 22 code examples of selenium.webdriver.common.desired_capabilities.DesiredCapabilities.CHROME(). 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.common.desired_capabilities.DesiredCapabilities , 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: DriverFactory.py    From qxf2-page-object-model with MIT License 10 votes vote down vote up
def run_sauce_lab(self,os_name,os_version,browser,browser_version):
        "Run the test in sauce labs when remote flag is 'Y'"
        #Get the sauce labs credentials from sauce.credentials file
        USERNAME = remote_credentials.USERNAME
        PASSWORD = remote_credentials.ACCESS_KEY
        if browser.lower() == 'ff' or browser.lower() == 'firefox':
            desired_capabilities = DesiredCapabilities.FIREFOX
        elif browser.lower() == 'ie':
            desired_capabilities = DesiredCapabilities.INTERNETEXPLORER
        elif browser.lower() == 'chrome':
            desired_capabilities = DesiredCapabilities.CHROME
        elif browser.lower() == 'opera':
            desired_capabilities = DesiredCapabilities.OPERA
        elif browser.lower() == 'safari':
            desired_capabilities = DesiredCapabilities.SAFARI
        desired_capabilities['version'] = browser_version
        desired_capabilities['platform'] = os_name + ' '+os_version


        return webdriver.Remote(command_executor="http://%s:%s@ondemand.saucelabs.com:80/wd/hub"%(USERNAME,PASSWORD),
                desired_capabilities= desired_capabilities) 
Example #3
Source File: DriverFactory.py    From makemework with MIT License 8 votes vote down vote up
def run_browserstack(self,os_name,os_version,browser,browser_version,remote_project_name,remote_build_name):
        "Run the test in browser stack when remote flag is 'Y'"
        #Get the browser stack credentials from browser stack credentials file
        USERNAME = remote_credentials.USERNAME
        PASSWORD = remote_credentials.ACCESS_KEY
        if browser.lower() == 'ff' or browser.lower() == 'firefox':
            desired_capabilities = DesiredCapabilities.FIREFOX            
        elif browser.lower() == 'ie':
            desired_capabilities = DesiredCapabilities.INTERNETEXPLORER
        elif browser.lower() == 'chrome':
            desired_capabilities = DesiredCapabilities.CHROME            
        elif browser.lower() == 'opera':
            desired_capabilities = DesiredCapabilities.OPERA        
        elif browser.lower() == 'safari':
            desired_capabilities = DesiredCapabilities.SAFARI
        desired_capabilities['os'] = os_name
        desired_capabilities['os_version'] = os_version
        desired_capabilities['browser_version'] = browser_version
        if remote_project_name is not None:
            desired_capabilities['project'] = remote_project_name
        if remote_build_name is not None:
            desired_capabilities['build'] = remote_build_name+"_"+str(datetime.now().strftime("%c"))

        return webdriver.Remote(RemoteConnection("http://%s:%s@hub-cloud.browserstack.com/wd/hub"%(USERNAME,PASSWORD),resolve_ip= False),
            desired_capabilities=desired_capabilities) 
Example #4
Source File: DriverFactory.py    From makemework with MIT License 8 votes vote down vote up
def run_sauce_lab(self,os_name,os_version,browser,browser_version):
        "Run the test in sauce labs when remote flag is 'Y'"
        #Get the sauce labs credentials from sauce.credentials file
        USERNAME = remote_credentials.USERNAME
        PASSWORD = remote_credentials.ACCESS_KEY
        if browser.lower() == 'ff' or browser.lower() == 'firefox':
            desired_capabilities = DesiredCapabilities.FIREFOX            
        elif browser.lower() == 'ie':
            desired_capabilities = DesiredCapabilities.INTERNETEXPLORER
        elif browser.lower() == 'chrome':
            desired_capabilities = DesiredCapabilities.CHROME            
        elif browser.lower() == 'opera':
            desired_capabilities = DesiredCapabilities.OPERA        
        elif browser.lower() == 'safari':
            desired_capabilities = DesiredCapabilities.SAFARI
        desired_capabilities['version'] = browser_version
        desired_capabilities['platform'] = os_name + ' '+os_version
        
        
        return webdriver.Remote(command_executor="http://%s:%s@ondemand.saucelabs.com:80/wd/hub"%(USERNAME,PASSWORD),
                desired_capabilities= desired_capabilities) 
Example #5
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 #6
Source File: DriverFactory.py    From qxf2-page-object-model with MIT License 8 votes vote down vote up
def run_browserstack(self,os_name,os_version,browser,browser_version,remote_project_name,remote_build_name):
        "Run the test in browser stack when remote flag is 'Y'"
        #Get the browser stack credentials from browser stack credentials file
        USERNAME = remote_credentials.USERNAME
        PASSWORD = remote_credentials.ACCESS_KEY
        if browser.lower() == 'ff' or browser.lower() == 'firefox':
            desired_capabilities = DesiredCapabilities.FIREFOX
        elif browser.lower() == 'ie':
            desired_capabilities = DesiredCapabilities.INTERNETEXPLORER
        elif browser.lower() == 'chrome':
            desired_capabilities = DesiredCapabilities.CHROME
        elif browser.lower() == 'opera':
            desired_capabilities = DesiredCapabilities.OPERA
        elif browser.lower() == 'safari':
            desired_capabilities = DesiredCapabilities.SAFARI
        desired_capabilities['os'] = os_name
        desired_capabilities['os_version'] = os_version
        desired_capabilities['browser_version'] = browser_version
        if remote_project_name is not None:
            desired_capabilities['project'] = remote_project_name
        if remote_build_name is not None:
            desired_capabilities['build'] = remote_build_name+"_"+str(datetime.now().strftime("%c"))

        return webdriver.Remote(RemoteConnection("http://%s:%s@hub-cloud.browserstack.com/wd/hub"%(USERNAME,PASSWORD),resolve_ip= False),
            desired_capabilities=desired_capabilities) 
Example #7
Source File: test_config_driver.py    From toolium with Apache License 2.0 6 votes vote down vote up
def test_create_remote_driver_chrome(webdriver_mock, config):
    config.set('Driver', 'type', 'chrome')
    server_url = 'http://10.20.30.40:5555'
    utils = mock.MagicMock()
    utils.get_server_url.return_value = server_url
    config_driver = ConfigDriver(config, utils)

    # Chrome options mock
    chrome_options = mock.MagicMock()
    chrome_options.to_capabilities.return_value = {'goog:chromeOptions': 'chrome options'}
    config_driver._create_chrome_options = mock.MagicMock(return_value=chrome_options)

    config_driver._create_remote_driver()
    capabilities = DesiredCapabilities.CHROME.copy()
    capabilities['goog:chromeOptions'] = 'chrome options'
    webdriver_mock.Remote.assert_called_once_with(command_executor='%s/wd/hub' % server_url,
                                                  desired_capabilities=capabilities) 
Example #8
Source File: test_config_driver.py    From toolium with Apache License 2.0 6 votes vote down vote up
def test_create_remote_driver_chrome_old_selenium(webdriver_mock, config):
    config.set('Driver', 'type', 'chrome')
    server_url = 'http://10.20.30.40:5555'
    utils = mock.MagicMock()
    utils.get_server_url.return_value = server_url
    config_driver = ConfigDriver(config, utils)

    # Chrome options mock
    chrome_options = mock.MagicMock()
    chrome_options.to_capabilities.return_value = {'chromeOptions': 'chrome options'}
    config_driver._create_chrome_options = mock.MagicMock(return_value=chrome_options)

    config_driver._create_remote_driver()
    capabilities = DesiredCapabilities.CHROME.copy()
    capabilities['chromeOptions'] = 'chrome options'
    webdriver_mock.Remote.assert_called_once_with(command_executor='%s/wd/hub' % server_url,
                                                  desired_capabilities=capabilities) 
Example #9
Source File: custom_driver.py    From king-bot with MIT License 6 votes vote down vote up
def remote(self) -> None:
        if not self.debug:
            log("debug mode is turned off, can't reuse old session")
            return

        file = open(self.current_session_path, "r")
        content = file.read()
        lines = content.split(";")
        url = lines[0]
        session = lines[1]

        self.driver = webdriver.Remote(
            command_executor=url, desired_capabilities=DesiredCapabilities.CHROME
        )
        self.driver.session_id = session

        self.set_config() 
Example #10
Source File: seleniumdriver.py    From media-scraper with MIT License 5 votes vote down vote up
def get(driverType, localDriver=True, path='.'):
    driverType = str(driverType)
    if driverType == 'PhantomJS':
        # phantomjs_options.add_argument("--disable-web-security")
        if localDriver:
            source = get_source(driverType, path)
            driver = webdriver.PhantomJS(executable_path=source, service_log_path=join(path, 'phantomjs.log'), service_args=["--remote-debugger-port=9000", "--web-security=false"])
            # driver = webdriver.PhantomJS(executable_path=source, service_args=["--remote-debugger-port=9000", "--web-security=false"])
        else:
            driver = webdriver.PhantomJS(service_log_path=join(path, 'phantomjs.log'), service_args=["--remote-debugger-port=9000", "--web-security=false"])
            # driver = webdriver.PhantomJS(service_args=["--remote-debugger-port=9000", "--web-security=false"])
    elif driverType == 'Chrome':
        desired = DesiredCapabilities.CHROME
        desired['loggingPrefs'] = {'browser': 'ALL'}
        chrome_options = Options()
        chrome_options.add_argument("--start-maximized")
        chrome_options.add_argument("--disable-infobars")
        chrome_options.add_argument("--disable-web-security")
        # chrome_options.add_argument("--window-size=800,600")
        # chrome_options.add_argument("--headless") # will not show the Chrome browser window
        if localDriver:
            source = get_source(driverType, path)
            driver = webdriver.Chrome(executable_path=source, service_log_path=join(path, 'chromedriver.log'), desired_capabilities=desired, chrome_options=chrome_options)
        else:
            driver = webdriver.Chrome(service_log_path=join(path, 'chromedriver.log'), desired_capabilities=desired, chrome_options=chrome_options)
    elif driverType == 'Firefox':
        # desired = DesiredCapabilities.FIREFOX
        # desired['loggingPrefs'] = {'browser': 'ALL'}
        firefox_options = Options()
        firefox_options.add_argument("--start-maximized")
        firefox_options.add_argument("--disable-infobars")
        if localDriver:
            source = get_source(driverType, path)
            driver = webdriver.Firefox(executable_path=source, service_log_path=join(path, 'geckodriver.log'), firefox_options=firefox_options)
        else:
            driver = webdriver.Firefox(service_log_path=join(path, 'geckodriver.log'), firefox_options=firefox_options)
    return driver 
Example #11
Source File: seleniumdriver.py    From lf2gym with MIT License 5 votes vote down vote up
def get(driverType, localDriver=True, headless=False, path='.'):
    driverType = str(driverType)
    if driverType == 'PhantomJS':
        # phantomjs_options.add_argument("--disable-web-security")
        if localDriver:
            source = get_source(driverType, path)
            driver = webdriver.PhantomJS(executable_path=source, service_log_path=join(path, 'phantomjs.log'), service_args=["--remote-debugger-port=9000", "--web-security=false"])
            # driver = webdriver.PhantomJS(executable_path=source, service_args=["--remote-debugger-port=9000", "--web-security=false"])
        else:
            driver = webdriver.PhantomJS(service_log_path=join(path, 'phantomjs.log'), service_args=["--remote-debugger-port=9000", "--web-security=false"])
            # driver = webdriver.PhantomJS(service_args=["--remote-debugger-port=9000", "--web-security=false"])
    elif driverType == 'Chrome':
        desired = DesiredCapabilities.CHROME
        desired['loggingPrefs'] = {'browser': 'ALL'}
        chrome_options = Options()
        chrome_options.add_argument("--start-maximized")
        chrome_options.add_argument("--disable-infobars")
        chrome_options.add_argument("--disable-web-security")
        # chrome_options.add_argument("--window-size=800,600")
        if headless:
            chrome_options.add_argument("--headless") # will not show the Chrome browser window
        if localDriver:
            source = get_source(driverType, path)
            driver = webdriver.Chrome(executable_path=source, service_log_path=join(path, 'chromedriver.log'), desired_capabilities=desired, chrome_options=chrome_options)
        else:
            driver = webdriver.Chrome(service_log_path=join(path, 'chromedriver.log'), desired_capabilities=desired, chrome_options=chrome_options)
    elif driverType == 'Firefox':
        # desired = DesiredCapabilities.FIREFOX
        # desired['loggingPrefs'] = {'browser': 'ALL'}
        firefox_options = Options()
        firefox_options.add_argument("--start-maximized")
        firefox_options.add_argument("--disable-infobars")
        if localDriver:
            source = get_source(driverType, path)
            driver = webdriver.Firefox(executable_path=source, service_log_path=join(path, 'geckodriver.log'), firefox_options=firefox_options)
        else:
            driver = webdriver.Firefox(service_log_path=join(path, 'geckodriver.log'), firefox_options=firefox_options)
    return driver 
Example #12
Source File: SeleniumDrivers.py    From AutoTriageBot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self):
        try:
            self.driver = webdriver.Remote(command_executor='http://chrome:4444/wd/hub',
                                           desired_capabilities=DesiredCapabilities.CHROME)
        except URLError as e:
            print("Failed to connect!")
            raise e 
Example #13
Source File: webdriver.py    From expressvpn_leak_testing with MIT License 5 votes vote down vote up
def driver(self, browser):
        self._start_server()
        command_executor = 'http://127.0.0.1:4444/wd/hub'

        if browser == 'firefox':
            return webdriver.Remote(command_executor=command_executor,
                                    desired_capabilities=DesiredCapabilities.FIREFOX)
        if browser == 'chrome':
            return webdriver.Remote(command_executor=command_executor,
                                    desired_capabilities=DesiredCapabilities.CHROME)
        if browser == 'phantom':
            return webdriver.PhantomJS()
        raise XVEx("{} is not supported on {}".format(browser, self._device.os_name())) 
Example #14
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 #15
Source File: browser.py    From browsertrix with MIT License 5 votes vote down vote up
def _init_caps(self):
        caps = DesiredCapabilities.CHROME

        if self.readlog:
            caps['loggingPrefs'] = {'performance': 'ALL'}
            caps['chromeOptions'] = {'perfLoggingPrefs': {'enableTimeline': False, 'enablePage': False}}

        return caps 
Example #16
Source File: 2.3_remote_sample.py    From DevAuto with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        self.driver = webdriver.Remote(
            command_executor="http://127.0.0.1:4444/wd/hub",
            desired_capabilities=DesiredCapabilities.CHROME
        ) 
Example #17
Source File: browser.py    From vanguard-api with MIT License 5 votes vote down vote up
def __init__(self):
        self.remote =  "http://selenium:4444/wd/hub"
        self.browser_type = DesiredCapabilities.CHROME

        self.browser = None 
Example #18
Source File: test_config_driver.py    From toolium with Apache License 2.0 5 votes vote down vote up
def test_create_local_driver_chrome(webdriver_mock, config):
    config.set('Driver', 'type', 'chrome')
    config.set('Driver', 'chrome_driver_path', '/tmp/driver')
    config_driver = ConfigDriver(config)
    config_driver._create_chrome_options = lambda: 'chrome options'

    config_driver._create_local_driver()
    webdriver_mock.Chrome.assert_called_once_with('/tmp/driver', desired_capabilities=DesiredCapabilities.CHROME,
                                                  chrome_options='chrome options') 
Example #19
Source File: screenshot.py    From cstar_perf with Apache License 2.0 4 votes vote down vote up
def get_graph_png(url, image_path=None, timeout=60, x_crop=None, y_crop=None):
    host = start_selenium_grid()
    print "Fetching screenshot of url " + url

    driver = webdriver.Remote(
        command_executor="http://" + host + ":4444/wd/hub",
        desired_capabilities=DesiredCapabilities.CHROME)

    driver.get(url)
    logging.info("Retrieving page, waiting for page to render: {url}".format(url=url))
    try:
        element = WebDriverWait(driver, timeout).until(
            EC.presence_of_element_located((By.ID, "svg_container"))
        )

        imageBytes = driver.get_screenshot_as_png()

        if x_crop is not None or y_crop is not None:
            image = Image.open(BytesIO(imageBytes))

            box = image.getbbox()
            left = 0
            upper = 0
            right = box[2]
            lower = box[3]

            if x_crop is not None:
                right = x_crop
            if y_crop is not None:
                lower = y_crop

            image = image.crop( (left, upper, right, lower) )

            newBytes = BytesIO()
            image.save(newBytes, "PNG")
            imageBytes = newBytes.getvalue()

        if image_path:
            logging.info("Saved image: {image_path}".format(image_path=image_path))
            with open(image_path, 'wb') as f:
                f.write(imageBytes)
        else:
            return imageBytes
    finally:
        driver.quit() 
Example #20
Source File: app.py    From ESPN-Fantasy-Basketball with MIT License 4 votes vote down vote up
def run_selenium(url, is_season_data, league_id):
    options = webdriver.ChromeOptions()
    options.add_argument('headless')
    options.add_argument('no-sandbox')
    options.add_argument('disable-dev-shm-usage')
    capa = DesiredCapabilities.CHROME
    capa["pageLoadStrategy"] = "none"
    driver = webdriver.Chrome(chrome_options=options, desired_capabilities=capa)
    try:
        app.logger.info('%s - Starting selenium', league_id)
        driver.get(url)
        app.logger.info('%s - Waiting for element to load', league_id)
        # Season standings have a different URL than weekly scoreboard

        if is_season_data:
            WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.CLASS_NAME, 'Table2__sub-header')))
        else:
            WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.CLASS_NAME, 'Table2__header-row')))
        app.logger.info('%s - Element loaded. Sleeping started to get latest data.', league_id)
        time.sleep(5)
        plain_text = driver.page_source
        soup = BeautifulSoup(plain_text, 'html.parser')
        app.logger.info('%s - Got BeautifulSoup object', league_id)
    except Exception as ex:
        app.logger.error('%s - Could not get page source.', league_id, ex)
        soup = None
    finally:
        driver.quit()
    return soup 
Example #21
Source File: selescrape.py    From anime-downloader with The Unlicense 4 votes vote down vote up
def driver_select(): #
    '''
    it configures what each browser should do 
    and gives the driver variable that is used 
    to perform any actions below this function.
    '''
    browser = get_browser_config()
    data_dir = get_data_dir()
    executable = get_browser_executable()
    driver_binary = get_driver_binary()
    binary = None if not driver_binary else driver_binary
    if browser == 'firefox':
        fireFoxOptions = webdriver.FirefoxOptions()
        fireFoxOptions.headless = True
        fireFoxOptions.add_argument('--log fatal')
        if binary == None:  
            driver = webdriver.Firefox(options=fireFoxOptions, service_log_path=os.path.devnull)
        else:
            try:
                driver = webdriver.Firefox(options=fireFoxOptions, service_log_path=os.path.devnull)
            except:
                driver = webdriver.Firefox(executable_path=binary, options=fireFoxOptions, service_log_path=os.path.devnull)
    elif browser == 'chrome':
        from selenium.webdriver.chrome.options import Options
        chrome_options = Options()
        chrome_options.add_argument("--headless")
        chrome_options.add_argument("--disable-gpu")
        profile_path = os.path.join(data_dir, 'Selenium_chromium')
        log_path = os.path.join(data_dir, 'chromedriver.log')
        chrome_options.add_argument(f'--log-path {log_path}')
        chrome_options.add_argument(f"--user-data-dir={profile_path}")
        chrome_options.add_argument("--no-sandbox")
        chrome_options.add_argument("--window-size=1920,1080")
        chrome_options.add_argument(f'user-agent={get_random_header()}')
        if binary == None:
            if executable == None:
                driver = webdriver.Chrome(options=chrome_options)
            else:
                from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
                cap = DesiredCapabilities.CHROME
                cap['binary_location'] = executable
                driver = webdriver.Chrome(desired_capabilities=cap, options=chrome_options)
        else:
            if executable == None:
                driver = webdriver.Chrome(options=chrome_options)
            else:
                from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
                cap = DesiredCapabilities.CHROME
                cap['binary_location'] = executable
                driver = webdriver.Chrome(executable_path=binary, desired_capabilities=cap, options=chrome_options)
    return driver 
Example #22
Source File: webdriver.py    From wagtail-tag-manager with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
def init_browser(self):
        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")

        self.browser = webdriver.Remote(
            getattr(settings, "WTM_CHROMEDRIVER_URL", "http://0.0.0.0:4444/wd/hub"),
            DesiredCapabilities.CHROME,
            options=options,
        )
        self.browser.implicitly_wait(30)