Code doesn't recognize chromedriver.exe as a file - python

So i'm new with python, and got interested with WebDriver and its possible applications. So i've written this just to test that all the necessary libraries are installed.
from selenium import webdriver
import time
driver = webdriver.Chrome(executable_path= r'chromedriver.exe')
driver.get('http://www.google.com')
And once i write python3 nameOfCode.py the result is an error as it so often is. The error(s) are
macs-MacBook-Pro:Desktop mac$ python3 testSelenium.py
Traceback (most recent call last):
File "testSelenium.py", line 5, in <module>
driver = webdriver.Chrome(executable_path= mac/Desktop/chromedriver.exe)
NameError: name 'mac' is not defined
macs-MacBook-Pro:Desktop mac$ python3 testSelenium.py
Traceback (most recent call last):
File "testSelenium.py", line 5, in <module>
driver = webdriver.Chrome(executable_path= Desktop/chromedriver.exe)
NameError: name 'Desktop' is not defined
macs-MacBook-Pro:Desktop mac$ python3 testSelenium.py
Traceback (most recent call last):
File "testSelenium.py", line 5, in <module>
driver = webdriver.Chrome(executable_path= chromedriver.exe)
NameError: name 'chromedriver' is not defined
macs-MacBook-Pro:Desktop mac$ python3 testSelenium.py
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver.exe': 'chromedriver.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "testSelenium.py", line 5, in <module>
driver = webdriver.Chrome(executable_path= r'chromedriver.exe')
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Sorry if this is much :))
Dario

The last line says it all...
'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
If you are using Windows:
You need to add the location of "chromedriver.exe" to your environment variable named PATH. You should be able to find the dialog through the start menu search (search for: environment variables), then find the variable named PATH (not case sensitive). If it doesn't exist, create it. The contents of this variable is a list of folder locations separated by semicolons, and the folder containing "chromedriver.exe" needs to be there.
If you're on a Mac: (I don't have one so I can't confirm these methods)
edit "/etc/paths" file to have the location of the executable, or put:
PATH="${PATH}:/some/other/directory:/another/place/scripts/live:"
export $PATH
somewhere in your .bash_profile file

Related

Error when using "webdriver.Chrome()" in selenium [duplicate]

This question already has answers here:
Error message: "'chromedriver' executable needs to be available in the path"
(33 answers)
Closed 3 years ago.
When I use "webdriver.Chrome()". I encountering an error when running this code:
from selenium import webdriver
driver = webdriver.Chrome()
Here's the error that showes up:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1178, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
driver = webdriver.Chrome()
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
I don't have any idea what to make of this. And I haven't found anyone with the same issue. Anyone know a fix?
You need to chromedriver binary and the path of binary as below:
driver = webdriver.Chrome('/usr/local/bin/chromedriver.exe')
Download your chromedriver as per your chrome version from below location :
https://chromedriver.storage.googleapis.com/index.html

Error "Service.py"

I'm new in Python and Pycharm and have some problem understanding this message:
Traceback (most recent call last):
File "C:\Users\reyde\PycharmProjects\Liderws\venv\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 997, in _execute_child
startupinfo)
PermissionError: [WinError 5] Acceso denegado
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/reyde/PycharmProjects/Liderws/Lider_ws.py", line 48, in <module>
browser21 = webdriver.Chrome(executable_path=rutaChromeDriver)
File "C:\Users\reyde\PycharmProjects\Liderws\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
self.service.start()
File "C:\Users\reyde\PycharmProjects\Liderws\venv\lib\site-packages\selenium\webdriver\common\service.py", line 88, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'Liderws' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Process finished with exit code 1
The error does say the webdriver has the wrong permissions. Is the path to ChromeDriver correct? Try to make the path something like:
browser21 = webdriver.Chrome(executable_path=C:\Webdrivers\chromedriver.exe)
Or wherever you have chromedriver saved, but make sure the path is directly to the exe.
Try redownloading the newest ChromeDriver available and place it in the folder you want. Don't forget to add it to system PATH and not just user.

Getting Exceptions when using Selenium to open browser [duplicate]

This question already has answers here:
Selenium using Python - Geckodriver executable needs to be in PATH
(36 answers)
Closed 5 years ago.
I am using python IDLE and after executing the following I am getting this import error
>>> from selenium import webdriver
>>> browser=webdriver.Firefox()
Traceback (most recent call last):
File "C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1224, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
browser=webdriver.Firefox()
File "C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 144, in __init__
self.service.start()
File "C:\Users\saish\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
Your exception is clear:
WebDriverException: Message: 'geckodriver' executable needs to be in
PATH.
You have to specify the path to the geckodriver:
driver = webdriver.Firefox(executable_path=r'/patToYour/geckodriver')

Python Selenium " 'geckodriver' executable needs to be in PATH"

Even though I have already put geckodriver in there and I restarted my computer, it still prints the same thing.
>>>from selenium import webdriver
>>>browser = webdriver.Firefox()
Traceback (most recent call last):
File "D:\Python\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "D:\Python\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "D:\Python\lib\subprocess.py", line 992, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\Python\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 144, in __init__
self.service.start()
File "D:\Python\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
And an error before that as well! Someone please help a newbie out. Image of the Path variable
You need to mention the path of the gecko driver executable. Below line will get you some idea.
driver=webdriver.Firefox(executable_path="add geckodriver.exe")
Hope this helps. Thanks.

Selinium Install trouble

I'm struggling to install selenium correctly, I tried to run the test script provided by the Selenium documentation. I have python 3 and python 2 installed, is it possible to force pip to install to python 2.7 and not 3? Maybe that is my issue? Any help or guidance would be appreciated.
Test Code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
1: First I installed selenium with pip
sudo pip install selenium
2: I tried to run the test script
python TestSelenium.py
Traceback Error:
Traceback (most recent call last):
File "TestSelenium.py", line 1, in <module>
from selenium import webdriver
ImportError: No module named selenium
3: Now if I try with python3 it finds it installed in /usr/lib/python3.5/site-packages/selenium
python3 TestSelenium.py
TraceBack Error:
Traceback (most recent call last):
File "/usr/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib64/python3.5/subprocess.py", line 950, in __init__
restore_signals, start_new_session)
File "/usr/lib64/python3.5/subprocess.py", line 1544, in _execute_child
raise child_exception_type(errno_num, err_msg)
FileNotFoundError: [Errno 2] No such file or directory: 'geckodriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "TestSelenium.py", line 4, in <module>
driver = webdriver.Firefox()
File "/usr/lib/python3.5/site-packages/selenium/webdriver/firefox/webdriver.py", line 135, in __init__
self.service.start()
File "/usr/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firefox.service.Service object at 0x7f9f9f184c18>>
Traceback (most recent call last):
File "/usr/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 163, in __del__
self.stop()
File "/usr/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 135, in stop
if self.process is None:
AttributeError: 'Service' object has no attribute 'process'
For using selenium Firefox webdriver, you have to download geckodriver. You can download it from "https://github.com/mozilla/geckodriver/releases".
Then specify the geckodriver path as given below:
browser = webdriver.Firefox(executable_path= your_geckogriver_path)
I think this will work. Please try it.

Categories

Resources