Every line of 'how to set chrome driver path in selenium' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.
7 def chrome_driver(executable_path=None, run_headless=False, 8 load_images=True, use_proxy=None): 9 '''Function to initialize ``selenium.webdriver.Chrome`` with extended options 10 11 Args: 12 executable_path (str): path to the chromedriver binary. If set to ``None`` selenium will serach for ``chromedriver`` in ``$PATH``. 13 run_headless (bool): boolean flag that indicates if chromedriver has to be headless (without GUI). 14 load_images (bool): boolean flag that indicates if Chrome has to render images. 15 use_proxy (str): use http proxy in format. 16 17 Returns: 18 selenium.webdriver.Chrome: created driver. 19 20 Note: 21 In order to create Chrome driver Selenium requires `Chrome `_ to be installed and `chromedriver `_ to be downloaded. 22 23 Warning: 24 Headless Chrome is shipping in Chrome 59 and in Chrome 60 for Windows. Update your Chrome browser if you want to use ``headless`` option. 25 ''' 26 chrome_options = webdriver.ChromeOptions() 27 if run_headless: 28 chrome_options.add_argument('headless') 29 if not load_images: 30 prefs = {'profile.managed_default_content_settings.images': 2} 31 chrome_options.add_experimental_option('prefs', prefs) 32 if use_proxy: 33 chrome_options.add_argument('proxy-server=' + use_proxy) 34 if executable_path: 35 driver = webdriver.Chrome(chrome_options=chrome_options, 36 executable_path=executable_path) 37 else: 38 driver = webdriver.Chrome(chrome_options=chrome_options) 39 return driver
23 def startBrowser(chrome_driver_path): 24 """Starts browser with predefined parameters""" 25 chrome_options = Options() 26 #chrome_options.add_argument('--headless') 27 driver = webdriver.Chrome(executable_path=chrome_driver_path, options=chrome_options) 28 return driver
156 def chromedriver(): 157 package_name = "io.appium.android.apis" 158 package_name = "com.xueqiu.android" 159 160 with driver(package_name) as dr: 161 print(dr.current_url) 162 elem = dr.find_element_by_xpath('//*[@id="phone-number"]') 163 elem.click() 164 elem.send_keys("123456")
10 def getDriver(): 11 driver = webdriver.Chrome() 12 return driver
24 def getDriver(browser): 25 chrome_options = webdriver.ChromeOptions() 26 chrome_options.add_argument("--incognito") 27 chrome_options.add_argument("--window-size=1440,900") 28 if browser.lower() == 'firefox': 29 driver = webdriver.Firefox() 30 elif browser.lower() == 'chrome': 31 driver = webdriver.Chrome('./chromedriver', chrome_options=chrome_options) 32 elif browser.lower() == 'chrome_linux': 33 driver = webdriver.Chrome('./chromedriver_linux64', chrome_options=chrome_options) 34 elif browser.lower() in ('phantomjs', 'headless'): 35 driver = webdriver.PhantomJS() 36 else: 37 print("WARNING: browser selection not valid, use PhantomJS as default") 38 driver = webdriver.PhantomJS() 39 return driver
20 def init_driver(): 21 driver = webdriver.Chrome() 22 driver.wait = WebDriverWait(driver, 5) 23 return driver
10 def getChromeBrowser(path: str = 'chromedriver', proxy: str = None, 11 implicitWaitTime: int = 30, incognito: bool = False, 12 headless: bool = False) -> webdriver.Chrome: 13 """ 14 Returns an instance of the webdriver for Chrome. 15 16 :param path: The path to your chromedriver\n 17 :param proxy: Proxy to connect to - ':\n 18 :param implicitWaitTime: Implicit wait time for the browser\n 19 :param incognito: Whether to open in incognito or not\n 20 :param headless: Run the browser in headless mode 21 """ 22 chromeOptions = webdriver.ChromeOptions() 23 chromeOptions.add_argument('disable-infobars') 24 25 if proxy: 26 chromeOptions.add_argument(f'--proxy-server={proxy}') 27 if incognito: 28 chromeOptions.add_argument("--incognito") 29 if headless: 30 chromeOptions.add_argument('--headless') 31 32 driver = webdriver.Chrome( 33 chrome_options=chromeOptions, executable_path=path) 34 driver.implicitly_wait(implicitWaitTime) 35 return driver
6 def get_driver(profile=None, headless=False, noimage=False, nonblock=False): 7 option = webdriver.ChromeOptions() 8 option.add_argument('disable-infobars') 9 option.add_argument('--hide-scrollbars') 10 # for headless 11 option.add_argument('window-size=1920x1080') 12 # possible bug? 13 option.add_argument('--disable-gpu') 14 # enable redirect 15 option.add_argument("--disable-web-security") 16 # disable log 17 option.add_argument("--log-level=3") 18 # disable selenium flag 19 option.add_experimental_option('excludeSwitches', ['enable-automation']) 20 21 if profile: 22 option.add_argument("user-data-dir={}".format(profile)) 23 if headless: 24 option.add_argument('--headless') 25 if noimage: 26 prefs = {"profile.managed_default_content_settings.images": 2} 27 option.add_experimental_option("prefs", prefs) 28 29 caps = DesiredCapabilities().CHROME 30 if nonblock: 31 # caps["pageLoadStrategy"] = "normal" # complete 32 # caps["pageLoadStrategy"] = "eager" # interactive 33 caps["pageLoadStrategy"] = "none" 34 35 # To avoid mysterious bug 36 option.add_argument( 37 "--remote-debugging-port={}".format(random.randint(10000, 65535))) 38 39 driver = webdriver.Chrome(options=option, desired_capabilities=caps) 40 return driver
282 def reset_chromedriver(self): 283 logging.info('Resetting chromedriver.') 284 self.chromedriver.quit() 285 self.chromedriver = get_headless_chrome_driver(CHROMEDRIVER_PATH)
43 def launch_driver(self, url, options, browser_build_path): 44 from webkitpy.thirdparty.autoinstalled.selenium.webdriver.firefox.options import Options 45 options = Options() 46 if browser_build_path: 47 binary_path = os.path.join(browser_build_path, 'firefox-bin') 48 options.binary_location = binary_path 49 driver_executable = self.webdriver_binary_path 50 from webkitpy.thirdparty.autoinstalled.selenium import webdriver 51 driver = webdriver.Firefox(firefox_options=options, executable_path=driver_executable) 52 super(LinuxFirefoxDriver, self).launch_webdriver(url, driver) 53 return driver