I am getting an error in using Selenium in python [duplicate] - python

This question already has answers here:
Error message: "'chromedriver' executable needs to be available in the path"
(33 answers)
Closed 5 years ago.
I tried using selenium for building a program but it just does not support web driver. I am getting the following error.
Traceback (most recent call last):
File "C:\Users\my dell\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\my dell\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\my dell\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 990, 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 "C:\Users\my dell\AppData\Local\Programs\Python\Python36-32\records\sel.py", line 2, in <module>
browser = webdriver.Chrome()
File "C:\Users\my dell\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
self.service.start()
File "C:\Users\my dell\AppData\Local\Programs\Python\Python36-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: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
Help would be appreciated.

it seems that you need to install chrome and chromedriver.
for debian linux:
apt install chromium
wget https://chromedriver.storage.googleapis.com/2.29/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo cp chromedriver /usr/bin/

Related

Exec format error - while executing sample code from selenium [duplicate]

from selenium import webdriver
browser = webdriver.Firefox(executable_path="/usr/bin/geckodriver")
browser.get('http://www.ubuntu.com/')
The entire stack trace looks like:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 160, in __init__
self.service.start()
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: 'geckodriver'
my path to geckodriver is:
/usr/bin/geckodriver
And selenium is in:
selenium in /usr/local/lib/python3.6/dist-packages (3.12.0)
Thanks in advance!
You have most probably installed a version of geckodriver that is meant for a different OS/platform! get the correct version from https://github.com/mozilla/geckodriver/releases and replace the one you have.
Use this command to install the latest chrome driver which supports selenium:
sudo apt-get install chromium-chromedriver

Chromedriver selenium may have wrong permission on Mac [duplicate]

This question already has answers here:
'Webdrivers' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
(22 answers)
Closed 6 months ago.
I am new at Python and selenium and I want to build an webdriver or bot respectively. I tried to execute the code below with inserting "python3 main.py" and with running the code on VS code but it is not working. The error result is enclosed. I am using Mac. The chromedriver exec is in the same main folder like the code I am writing, so actually the Path should be right. I tried different ways to solve my problem but non of them worked. I have the right chromedriver version on my mac and I even allowed my system to open the chromedriver folder.
from selenium import webdriver
browser = webdriver.Chrome('/Users/user/Desktop/it_projects/python-google-automation/src/chromedriver')
browser.get('https://www.google.com')
Error: "user#MacBook-Air-von-User python-google-automation % python3 main.py
/Users/user/Desktop/it_projects/python-google-automation/main.py:4: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(executable_path='/Users/user/Desktop/it_projects/python-google-automation/src/chromedriver')
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/selenium/webdriver/common/service.py", line 71, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 969, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/subprocess.py", line 1845, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: '/Users/user/Desktop/it_projects/python-google-automation/src/chromedriver'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/user/Desktop/it_projects/python-google-automation/main.py", line 4, in <module>
driver = webdriver.Chrome(executable_path='/Users/user/Desktop/it_projects/python-google-automation/src/chromedriver')
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/selenium/webdriver/chromium/webdriver.py", line 89, in __init__
self.service.start()
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/selenium/webdriver/common/service.py", line 86, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable may have wrong permissions. Please see https://chromedriver.chromium.org/home
user#MacBook-Air-von-User python-google-automation % "
#Oxgur Sahin, you have to give executable permission to your chromedriver file /Users/user/Desktop/it_projects/python-google-automation/src/chromedriver.

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

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.

Categories

Resources