It looks like after opening the browser, Selenium cannot move on for some reasons I can't figure out. No error was ever displayed.
Here is my simple code:
import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# Using Chrome to access web
browser = webdriver.Chrome(executable_path = "C:\Program Files\Google\Chrome\Application\chrome.exe")
print ("done")
# Open YouTube website
browser.get("https://www.youtube.com/")
The browser opens just fine, but the print("done") statement is never executed. (In the terminal the word "done" was never printed. So, it infers that the selenium has never finished executing the command to open the browser even though the browser has opened, and I have waited for several minutes.
Thanks in advance to our wonderful StackOverflow community!
CodePudding user response:
You should use chromedriver.exe
instead of the path to your chrome.exe
.
Download the chromedriver
suitable for your chrome version, from here:
donwload Chromedriver.exe
Afterwards, do something like this:
browser = webdriver.Chrome("E:\YourPathToChromeDriver\chromedriver.exe")
CodePudding user response:
Try these steps:
- Check your Google Chrome version here "chrome://settings/help"
- Download chromedriver.exe from "https://chromedriver.chromium.org/downloads"
- Change executable path to newly downloaded file.
CodePudding user response:
The reason is because you are using chrome.exe
which is for browser. Instead you should download chromdriver.exe
, Please download from here. You should download Latest stable release: ChromeDriver 94.0.4606.61
(as on 3rd-oct-2021). Keep that in your automation directory and any directory of your preference.
driver_path = r'C:\\Users\\username\\Desktop\\Automation\\chromedriver.exe'
driver = webdriver.Chrome(executable_path = driver_path)
Note that, in place of driver_path
, you should give the path where you've kept the chromdriver.exe