I am trying to use selenium to test a webpage I am building.
I downloaded chrome driver and placed the executable in the path below.
I know the path is correct.
driver = webdriver.Chrome(executable_path=r'C:\Python\chromedriver.exe')
What can I do to address this or what am I missing?
Try calling the file without the ".exe" extension.
I use chromedriver but I never need to call the extension.
driver = webdriver.Chrome('C:\Python\chromedriver')
Related
Trying to create a webscraper via Selenium. Below code only gives data; in the browser and ends up with error.
from selenium import webdriver
options = webdriver.ChromeOptions()
website = ""
path = "/Users/lilly/Downloads/chromedriver"
driver = webdriver.Chrome(path)
driver.get(website)
#all_matches_button = driver.find_element_by_xpath('')
#all_matches_button.click()
#driver.quit()
Chrome browser: Version 104.0.5112.81 (latest)
Chrome driver: 104.0.5112.79 (latest)
Error message in Python:
selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist
Tried to reinstall Chrome driver, but not luck. (https://sites.google.com/chromium.org/driver/)
Currently working on my Windows, but above code works on my macbook. I noticed on my Macbook that the version of the Chrome browser and driver are the same (104.0.5112.79).
Also have to close all browser tabs before running the code. otherwise it will result in the below error:
InvalidArgumentException: Message: invalid argument: user data directory is already in use error using --user-data-dir
Also quite annoying..
Thanks.
L.
For Windows, you have to provide the file extension. In your Mac, the chrome driver executable file name is chromedriver. But for Windows, it is chromedriver.exe.
Change your path to the following and it will work. Make sure the executable file path is provided not just the folder.
path = "/Users/lilly/Downloads/chromedriver.exe"
So basically, I added geckodriver.exe to the environment variables Path on Windows 10, yet trying
from selenium import webdriver
driver=webdriver.Firefox()
still resulted in the error message that "Geckodriver" executables need to be installed on Path
Now, I installed Chrome and the chromedriver.exe file off the web and ran chromedriver on Selenium just fine
from selenium import webdriver
browser=webdriver.Chrome(r'c:\chromedriver\chromedriver.exe')
This works and Google Chrome is open, so now I try to add the path in Firefox and when the path suggestions are showing up, selenium doesn't even recognize the geckodriver.exe exists, and pathlib does recognize the Path('c:/geckodriver/geckodriver.exe').exists()==True.
browser=webdriver.Firefox(r'c:\geckodriver\geckodriver.exe')
NotADirectoryError
So selenium is saying that the .exe file that clearly exists does not exist. How do I solve this problem?
For FireFox webdriver you'll need to set the path like this:
browser=webdriver.Firefox(executable_path=r'c:\geckodriver\geckodriver.exe')
I'm up with python 3.8 and selenium but recently I downloaded the latest edge web driver zip file and runned the mswdedriver.exe from that and typed this code in my ide:
from selenium import webdriver
browser = webdriver.Edge('F:\za\python\Assistant\msedgedriver.exe')
browser.maximize_window()
browser.get(url='http://seleniumhq.org/')
but I see this error:
selenium.common.exceptions.WebDriverException: Message: 'MicrosoftEdgeDriver' executable needs to be
in PATH. Please download from http://go.microsoft.com/fwlink/?LinkId=619687
Can you help me friends?
Thanks in advance.
You need to give a path to the webdriver executable when you load a webdriver, or have it stored as an environment variable:
webdriver.Edge(executable_path="path/to/executable")
A web driver is essentially a special browser application, you must install that application before you can run anything with it.
Here's Edge's web driver download page. Or you can use the link from the error message http://go.microsoft.com/fwlink/?LinkId=619687
Here's a similar question Python Selenium Chrome Webdriver
The backslashes in the executable path need to be escaped, per Python syntax:
browser = webdriver.Edge('F:\\za\\python\\Assistant\\msedgedriver.exe')
This problem appears to me
you must put in "Bin Folder" the file "MicrosoftWebDriver.exe" as is , edit the previous name of edge webdriver to be "MicrosoftWebDriver.exe" and put it in the "Bin Folder"
You need to download the browser driver from here
After the download completes, extract the driver executable to your preferred location. Add the folder where the executable is located to your PATH environment variable.
Ok, so I decided to use selenium for some code, but it doesn't work. When I put the chromedriver in my path, manually, it still doesn't work. can anyone help. PS: I already pip installed selenium.
Also, I watch/read the other article on stack overflow about this problem, but it didn't help me.
If you put chromedriver in the home directory of the user running it, that should work. Would be helpful if you stated in your question what OS/version you are using.
This problem occurs when the .py file you are running cannot find chrome driver. the best thing you can do in this situation is that the chrome driver that you installed copy and paste it in same folder as your .py file and then keep your path blank. if you keep your path blank it basically means that the .py file will search the driver on in its folder so make sure you have chrome driver in the same folder ask .py file and then keep your web driver as:
driver = webdriver.Chrome()
Well add change the code to this
import os
path = os.path.join(os.path.dirname(os.path.realpath(__file__)) + r'\chromedriver')
driver = webdriver.Chrome(executable_path = path)
So what is does is it add the chrome webdriver from path to selenium webdriver. Make sure to add the chromedriver.exe file in the root of the folder.
I've been attempting to use the selenium webdriver with Google Chrome.
I have installed chromedriver, and set the path to it. This has been done correctly as when I run chromedriver in terminal I get the output
Starting ChromeDriver 2.38.552518
on port 9515
Only local connections are allowed
However, when I attempt to use the chromedriver on my python script:
from selenium import webdriver
driver = webdriver.Chrome()
I get this following error:
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'
I've tried multiple methods of specifying the direct path and also putting the chromedriver file in the folder the python script is in. But nothing seems to be working and they all give the same error!
Please Help!
edit:
Path has been set in bash profile as such:
export PATH="~/drivers/:${PATH}"
Attempted Path specified in the python script as such:
driver = webdriver.Chrome("~/drivers/chromedriver")
Still with the same error of:
No such file or directory: '~/drivers/chromedriver': '~/drivers/chromedriver'
Java can't understand ~/drivers/chromedriver, Because only Linux Shell understand ~ is user home folder, But Java can't.
So your should use absolute path like /home/<userA>/drivers/chromedriver or relative path like ../drivers/chromedriver
You have to set the Path :
driver = webdriver.Chrome('C:/path/to/chromedriver.exe')
download selenium server-standalone-3.12.0.jar
and try this in a terminal:
export CLASSPATH=".:selenium-server-standalone-3.12.0.jar"