Home > Enterprise >  Problems with Chrome webdriver
Problems with Chrome webdriver

Time:11-07

Getting started with using Chrome webdrivers and selenium. When I execute the code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait




driver = webdriver.Chrome(executable_path = \
                          r"C:\Users\payto\Downloads\chromedriver_win32.zip\chromedriver.exe")

I keep getting this error:

WebDriverException: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

I've looked up how to solve it, but anything I see says to install a webdriver...which I've already done. My Chrome version is 107 and that's the one I downloaded, so it should be working but it's not. Any tips?

CodePudding user response:

You can use webdriver_manager instead of constantly setting executable_path and chromedriver yourself.

For chrome driver:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

it will automatically download the appropriate chromedriver. if it's already loaded, it finds it in the cache and uses it directly.

CodePudding user response:

Solution

You can get rid of all driver versions issues by using ChromeDriverManager

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.maximize_window()
driver.get("https://www.google.com")

OR Fixing the issue in your existing code like .. Downloading a specific version of ChromeDriver you can use the following code block:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

s = Service('C:/Users/hp/Downloads/chromedriver/chromedriver.exe')
driver = webdriver.Chrome(service=s)

You can find more discussion here, hope this will help you.

  • Related