Python Selenium, error with loading up browser

Viewed 70

I've looked all over for what must be a very simple solution to this problem. All I've been trying to do is load Google Chrome using selenium but I keep getting this error:

selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create Chrome process.

I've looked at posts related to this problem and none seem to have a fix. So instead, I tried using Firefox, which led me to this error:

NotADirectoryError: [WinError 267] The directory name is invalid: 'D:\\Programming\\Python Packages\\Selenium stuff\\geckodriver.exe'

Now I've checked, and the directory name is definitely not invalid for Firefox, And I have no clue what the chrome issue is. Any clues on what I might be missing here? Here's my simple code:

from selenium import webdriver

driver = webdriver.Firefox("D:\\Programming\\Python Packages\\Selenium stuff\\geckodriver.exe")
driver.get("https://www.google.com")

I've made sure to check my versions of webdrivers are compatible with my browser versions, and I've tried changing the slashes "/" and "" in my code. No changes were made.

2 Answers

Along with Chrome version issue, you are missing the attribute to be given to initialize the browser executable_path

A sample snippet for Firefox browser:

from selenium import webdriver
driver = webdriver.Firefox(executable_path="C:/Webdriver/geckodriver.exe")
driver.get("https://www.google.com")

The same you can try with Chrome browser as well.

Try moving the file to an easier place to find, or directly copy the address from the file explorer. If none of that works, try a different browser or reinstall the driver.

Related