Recently all webdrivers that I try to use don't work correctly, and when I run the same code on another computer it works fine. The problems I get:
- Chrome and Firefox open but stuck at data and then 'selenium.common.exceptions.WebDriverException: Message: chrome not reachable' for example;
- Ms Edge won't even open and gives no error;
Already tried: installing and re-installing Selenium, Python, Pycharm, webdrivers of different versions, changed the PATH location, but the problem seems to be in my computer.
Simple code that I am trying to execute:
from selenium import webdriver
driver = webdriver.Chrome() #this is the function that isn't working
driver.get('https://www.google.com/')
Any suggestions?
CodePudding user response:
I don't know if this will help, but I believe that you need to specify the location of the ChromeDriver
or Google Chrome .exe
location before you call your WebDriver
. Once you specify the location of your ChromeDriver
then you should be able to use it at your disposal.
Sample Code For You
from selenium import webdriver
def get_chrome_driver():
"""This sets up our Chrome Driver and returns it as an object"""
path_to_chrome = "F:\Selenium_Drivers\Windows_Chrome85_Driver\chromedriver.exe"
chrome_options = webdriver.ChromeOptions()
# Browser is displayed in a custom window size
chrome_options.add_argument("window-size=1500,1000")
return webdriver.Chrome(executable_path = path_to_chrome,
options = chrome_options)
# Gets our chrome driver and opens our site
chrome_driver = get_chrome_driver()
chrome_driver.get("https://www.bbc.com/news/world")
chrome_driver.quit()
chrome_driver.service.stop()
CodePudding user response:
when you Intialize the webdriver its always recomended to specify the path of the respective browser like ChromeDriver for Chrome browser and GeckoDriver for Mozilla Firefox.
Or You can invoke WebDriver manager at the point which would handle this. Link: https://snyk.io/advisor/python/webdriver-manager