How to use get_chromedriver_version method in SeleniumBase

Best Python code snippet using SeleniumBase

session.py

Source:session.py Github

copy

Full Screen

...83 return HIWORD(ms)84 except:85 return "Unknown Version"86 87 def get_chromedriver_version(self):88 stream = os.popen('{}\\chromedriver.exe --version'.format(self.chromedriver_path))89 output = stream.read()90 chromedriver_version = re.search('\d*\.\d*\.\d*\.\d*', output).group().split('.')[0]91 return chromedriver_version92 93 def download_chromedriver(self):94 latest = requests.get('https://chromedriver.storage.googleapis.com/LATEST_RELEASE_{}'.format(self.chrome_version))95 wget.download('https://chromedriver.storage.googleapis.com/{}/chromedriver_win32.zip'.format(latest.text), '{}\\chromedriver_win32.zip'.format(self.chromedriver_path))96 with zipfile.ZipFile('{}\\chromedriver_win32.zip'.format(self.chromedriver_path), 'r') as zip_ref:97 zip_ref.extractall(self.chromedriver_path)98 99 os.remove(f'{self.chromedriver_path}\\chromedriver_win32.zip')100 101 if os.path.exists(f'{self.chromedriver_path}\\chromedriver.exe'):102 return True103 else: 104 return False105 106 def setup_browser(self):107 updated = True108 browser = None109 while True:110 if not os.path.exists(f'{self.chromedriver_path}\\chromedriver.exe'):111 if self.log:112 self.log.info('chromedriver.py não encontrado. Fazendo download...')113 else:114 print('chromedriver.py não encontrado. Fazendo download...')115 downloaded = self.download_chromedriver()116 else: 117 downloaded = True118 119 if downloaded:120 self.chromedriver_version = self.get_chromedriver_version()121 122 if int(self.chromedriver_version) != int(self.chrome_version):123 updated = False124 125 if self.log:126 self.log.info('Atualizando chromedriver...')127 else:128 print('Atualizando chromedriver...')129 130 self.download_chromedriver()131 self.chromedriver_version = self.get_chromedriver_version()132 self.chrome_version = self.get_chrome_version()133 updated = int(self.chromedriver_version) == int(self.chrome_version)134 else:135 continue136 if updated:137 self.options = webdriver.ChromeOptions()138 self.options.add_experimental_option("prefs", self.profile)139 if self.headless:140 self.options.add_argument('--headless')141 142 if self.profile_folder:143 if not os.path.exists(self.profile_folder):144 os.makedirs(self.profile_folder)145 ...

Full Screen

Full Screen

chromedriver.py

Source:chromedriver.py Github

copy

Full Screen

...42 google_process_return = google_process.stdout.read()43 return google_process_return.decode('utf-8')44def parse_version(chrome_version: str):45 return chrome_version.split()[2]46def get_chromedriver_version(chrome_version: str):47 url = 'https://chromedriver.storage.googleapis.com/'48 response = requests.get(url, headers=headers, params=params)49 response = TextResponse(body=response.content, url=url)50 for item in response.css('Prefix').extract():51 if chrome_version[0:7] in item:52 return re.compile(r'(\d.*\d)').search(item)53def download_chromedriver(chromedriver_version: str):54 headers = {55 'sec-ch-ua': '" Not;A Brand";v="99", "Google Chrome";v="91",'56 '"Chromium";v="91"',57 'sec-ch-ua-mobile': '?0',58 'Upgrade-Insecure-Requests': '1',59 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36'60 '(KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36',61 'Referer': 'https://chromedriver.storage.googleapis.com/'62 f'index.html?path={chromedriver_version}/',63 }64 url = 'https://chromedriver.storage.googleapis.com/'65 f'{chromedriver_version}/chromedriver_linux64.zip'66 with requests.get(url, headers, stream=True) as r:67 r.raise_for_status()68 with open('chromedriver.zip', 'wb') as f:69 for chunk in r.iter_content(chunk_size=1024):70 if chunk:71 f.write(chunk)72 g = subprocess.Popen("unzip chromedriver.zip && rm chromedriver.zip",73 shell=True, stdout=subprocess.PIPE)74 return g.stdout.read()75def main():76 download = False77 if(chromedriver_exists()):78 print('Chromedriver already exists')79 if(chromedriver_updated()):80 print('Chromedriver already updated')81 else:82 download = True83 else:84 download = True85 if (download is True):86 g = get_chrome_version()87 b = parse_version(g)88 version = get_chromedriver_version(b)89 download_chromedriver(version.group())90 print(f'👌 Chromedriver updated: {version.group()}')91 else:92 pass93if __name__ == '__main__':...

Full Screen

Full Screen

init_chromedriver.py

Source:init_chromedriver.py Github

copy

Full Screen

...24 driver = webdriver.Chrome(service=s, options=op)25 return driver26 except Exception as e:27 print(e)28def get_chromedriver_version(driver):29 try:30 print("\nchromedriver path -> {}".format(CHROMEDRIVER_PATH))31 print(32 "chromedriver version -> {}".format(driver.capabilities["browserVersion"])33 )34 except Exception as e:35 print(e)36 return driver.capabilities["browserVersion"]37# test...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run SeleniumBase automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful