Python Selenium Chrome Webdriver

Python Selenium Chrome Webdriver

You need to specify the path where your chromedriver is located.

  1. Download chromedriver for your desired platform from here.

  2. Place chromedriver on your system path, or where your code is.

  3. If not using a system path, link your chromedriver.exe (For non-Windows users, it's just called chromedriver):

    browser = webdriver.Chrome(executable_path=r"C:\path\to\chromedriver.exe")

    (Set executable_path to the location where your chromedriver is located.)

    If you've placed chromedriver on your System Path, you can shortcut by just doing the following:

    browser = webdriver.Chrome()

  4. If you're running on a Unix-based operating system, you may need to update the permissions of chromedriver after downloading it in order to make it executable:

    chmod +x chromedriver

  5. That's all. If you're still experiencing issues, more info can be found on this other StackOverflow article: Can't use chrome driver for Selenium

Selenium ChromeDriver issue using Webdriver Manager for Python

There are two issues in your code block as follows:

  • You need to import ChromeDriverManager from webdriver_manager.chrome
  • As per Webdriver Manager for Python download_and_install() isn't supported and you have to use install()

So your effective code block will be:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("http://www.python.org")

On windows-10 system the console output will be:

C:\Users\Admin\Desktop\Python Programs>python webdriver-manager_ChromeDriverManager.py
[WDM] -

[WDM] - ====== WebDriver manager ======
[WDM] - Current google-chrome version is 95.0.4638
[WDM] - Get LATEST driver version for 95.0.4638
[WDM] - There is no [win32] chromedriver for browser 95.0.4638 in cache
[WDM] - Get LATEST driver version for 95.0.4638
[WDM] - Trying to download new driver from https://chromedriver.storage.googleapis.com/95.0.4638.54/chromedriver_win32.zip
[WDM] - Driver has been saved in cache [C:\Users\Admin\.wdm\drivers\chromedriver\win32\95.0.4638.54]

DevTools listening on ws://127.0.0.1:50921/devtools/browser/c26df2aa-67aa-4264-b1dc-34d6148b9174

You can find a relevant detailed discussion in ModuleNotFoundError: No module named 'webdriver_manager' error even after installing webdrivermanager

Python: Selenium webdriver Chrome opens up browser but not the site selected

Please download latest chrome driver which support to your browser version :
you can download Latest Chrome driver from here, Here r denotes relative path::

from selenium import webdriver
driver = webdriver.Chrome(executable_path=r" path to your chromedriver.exe")
driver.maximize_window()
baseUrl = "https://www.google.com"
driver.get(baseUrl)

Python, selenium webdriver chrome, obtain page source from inside of many web elements

For each attraction index you can click it to open the details, get the details, close the details, get the list of attractions again and go for the next attraction.

Something like this should work:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver.get("https://www.google.com/travel/things-to-do/see-all?dest_mid=%2Fm%2F081m_&dest_state_type=sattd&dest_src=yts&q=Warszawa#ttdm=52.227486_21.004941_13&ttdmf=%252Fm%252F0862m")
wait = WebDriverWait(driver, 20)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.f4hh3d")))
time.sleep(1)
attractions = driver.find_elements_by_css_selector('div.f4hh3d')
for i in range(len(attractions)):
attractions = driver.find_elements_by_css_selector('div.f4hh3d')
attractions[i].click()
description = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'div[jsname="BEZjkb"] div[jsname="bN97Pc"]'))).text
#do with the description what you want
#close the attraction by clicking the button
driver.find_element_by_css_selector('div.reh1ld button')

How to fix chrome driver version issue in selenium and pyinstaller using python?

Your issue is unlikely to be the Chrome Driver version. One way to check it is simply to run the full script and see if Chromedriver launched correctly or not.

In general, my approach to debugging the Pyinstaller error will be following.

1: Make sure Pyinstaller is not at the newest version (3.6 is my personal preference). I am not sure what is the issue with the newer Pyinstaller but it always gives me trouble when packaging executable.

2: If downgrading Pyinstaller not working, make sure the standalone script itself can run with no bug.

3: If the error persists, copy-paste the error msg to Google.



Related Topics



Leave a reply



Submit