How do I add chromedriver to PATH? - selenium

I'm trying to follow Automate the Boring Stuff and am trying to do the selenium work. I’m running Linux using Mu. Here's the code I'm trying to run
from selenium import webdriver
chromedriver = “/lorenmspeer/Downloads/chromedriver.exe”
browser = webdriver.Chrome(executable_path=chromedriver)
url = “https://www.duckduckgo.com”
browser.get(url)
I’m getting this error:
Traceback (most recent call last):
File “/home/lorenmspeer/.local/share/mu/mu_venv-38-20210401-164244/lib/python3.8/site-packages/selenium/webdriver/common/service.py”, line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File “/usr/lib/python3.8/subprocess.py”, line 854, in init
self._execute_child(args, executable, preexec_fn, close_fds,
File “/usr/lib/python3.8/subprocess.py”, line 1702, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: ‘/lorenmspeer/Downloads/chromedriver.exe’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “/home/lorenmspeer/mu_code/seleniumTest22.py”, line 5, in
browser = webdriver.Chrome(executable_path=chromedriver)
File “/home/lorenmspeer/.local/share/mu/mu_venv-38-20210401-164244/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py”, line 73, in init
self.service.start()
File “/home/lorenmspeer/.local/share/mu/mu_venv-38-20210401-164244/lib/python3.8/site-packages/selenium/webdriver/common/service.py”, line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: ‘chromedriver.exe’ executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

To check where Chrome driver is installed on Linux run whereis chromedriver. Then, put this path to Chrome("your_path")
In my project it is specified in the folder I defined:
driver = webdriver.Chrome("/usr/lib/chromium-browser/chromedriver")
It should not have .exe resolution
For more info check docs:
https://chromedriver.chromium.org/getting-started
driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.

I found a solution. First I had to make the file executable:
chmod +x chromedriver
Then I moved it to PATH
sudo mv chromedriver /usr/local/bin/
This made the code launch the browser.

Related

OSError: [Errno 8] Exec format error: '/home/ec2-user/Desktop/chromedriver' error using Chromedriver in AWS EC2 ARM flavour machine

I have an EC2 machine from AWS with ARM flavour. I installed Python 3, and then used pip3 to install Selenium. I then downloaded the Linux version of chrome driver from here, unzipped it and kept the chromedriver file in Desktop. When I try to run code like this:
driver = webdriver.Chrome('/home/ec2-user/Desktop/chromedriver')
I get this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ec2-user/.local/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
service_log_path, service, keep_alive)
File "/home/ec2-user/.local/lib/python3.7/site-packages/selenium/webdriver/chromium/webdriver.py", line 90, in __init__
self.service.start()
File "/home/ec2-user/.local/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
creationflags=self.creationflags)
File "/usr/lib64/python3.7/subprocess.py", line 800, in __init__
restore_signals, start_new_session)
File "/usr/lib64/python3.7/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: '/home/ec2-user/Desktop/chromedriver'
Any idea how to fix this? May be a different combination of Linux flavour and chrome driver from somewhere else?
This error message...
OSError: [Errno 8] Exec format error: '/home/ec2-user/Desktop/chromedriver'
...implies that you are using an incorrect format of ChromeDriver executable.
Deep Dive
As you are using AWS EC2 ARM flavour you need to use the either ARM64 or ARM7 variant of ChromeDriver.
Additionally, you seem to have downloaded ChromeDriver v100.x where as the latest version of google-chrome is Chrome Version 99.0.4844.84
and you need the matching version of ChromeDriver as per the installed version of Google Chrome within the system.
Solution
As #Mark B pointed out in his comment you need to download the matching version of ChromeDriver as per the discussion Compile ChromeDriver on ARM

How to put chromedriver executable in a path [duplicate]

This question already has answers here:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH error with Headless Chrome
(1 answer)
WebDriverException: Message: 'chromedriver' executable needs to be in PATH while setting UserAgent through Selenium Chromedriver python
(1 answer)
Error Message: 'chromedriver' executable needs to be PATH
(2 answers)
Closed 2 years ago.
Traceback (most recent call last):
File "/Applications/project bitcoin/venv/lib/python3.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 775, in init
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/subprocess.py", line 1522, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/paulndam/Downloads/chromedriver 2/chromedriver 2.exe': 'C:/Users/paulndam/Downloads/chromedriver 2/chromedriver 2.exe'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Applications/project bitcoin/Browser Automation.py", line 3, in
browser = webdriver.Chrome('C:/Users/paulndam/Downloads/chromedriver 2/chromedriver 2.exe')
File "/Applications/project bitcoin/venv/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in init
self.service.start()
File "/Applications/project bitcoin/venv/lib/python3.7/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 2.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
If you are creating a Chrome web driver then you need to put the path of the ChromeDriver in the first parameter: browser = webdriver.Chrome(CHROMEDRIVER_PATH) where CHROMEDRIVER_PATH is a variable containing the path.

Cannot run dask-mpi with Python 3.7 -- timeout when connecting client to dask-mpi scheduler

I'm attempting to run the Dask-MPI "Getting Started" (http://mpi.dask.org/en/latest/) example in a fresh Anaconda environment.
I set up an environment using
conda create -n dask-mpi -c conda-forge python=3.7 dask-mpi
conda activate dask-mpi
Inside the environment, I run
mpirun -np 4 dask-mpi --scheduler-file ./scheduler.json
Then, from a python interpreter on the same machine (and in the same folder), I run
from dask.distributed import Client
client = Client(scheduler_file='/path/to/scheduler.json')
This results in the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/nleaf/anaconda3/envs/dask-mpi/lib/python3.7/site-packages/distributed/client.py", line 712, in __init__
self.start(timeout=timeout)
File "/home/nleaf/anaconda3/envs/dask-mpi/lib/python3.7/site-packages/distributed/client.py", line 858, in start
sync(self.loop, self._start, **kwargs)
File "/home/nleaf/anaconda3/envs/dask-mpi/lib/python3.7/site-packages/distributed/utils.py", line 331, in sync
six.reraise(*error[0])
File "/home/nleaf/anaconda3/envs/dask-mpi/lib/python3.7/site-packages/six.py", line 693, in reraise
raise value
File "/home/nleaf/anaconda3/envs/dask-mpi/lib/python3.7/site-packages/distributed/utils.py", line 316, in f
result[0] = yield future
File "/home/nleaf/anaconda3/envs/dask-mpi/lib/python3.7/site-packages/tornado/gen.py", line 729, in run
value = future.result()
File "/home/nleaf/anaconda3/envs/dask-mpi/lib/python3.7/site-packages/tornado/gen.py", line 736, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File "/home/nleaf/anaconda3/envs/dask-mpi/lib/python3.7/site-packages/distributed/client.py", line 954, in _start
yield self._ensure_connected(timeout=timeout)
File "/home/nleaf/anaconda3/envs/dask-mpi/lib/python3.7/site-packages/tornado/gen.py", line 729, in run
value = future.result()
File "/home/nleaf/anaconda3/envs/dask-mpi/lib/python3.7/site-packages/tornado/gen.py", line 736, in run
yielded = self.gen.throw(*exc_info) # type: ignore
File "/home/nleaf/anaconda3/envs/dask-mpi/lib/python3.7/site-packages/distributed/client.py", line 1015, in _ensure_connected
timedelta(seconds=timeout), self._update_scheduler_info()
File "/home/nleaf/anaconda3/envs/dask-mpi/lib/python3.7/site-packages/tornado/gen.py", line 729, in run
value = future.result()
tornado.util.TimeoutError: Timeout
The terminal that I ran dask-mpi from does not have any output which would indicate that something is trying to connect. I have verified that the port in question, 8786, is open. I've also verified via debugger that the client is getting the correct address from the scheduler file.
I've tried this in quite a few different environments and on a few different machines, including a fresh Ubuntu 18.04 docker container. I'm completely at a loss for what steps I might be missing.
It turns out this was due to an error in newer versions of dask.distributed (1.25.3) which broke the behavior of dask-mpi. This seems to be fixed as of dask-mpi 1.0.3 (https://github.com/dask/dask-mpi/releases/tag/1.0.3).

Selenium firefox webdriver with virtualenv: Exec format error

I am using Selenium and Virtualenv in Ubuntu14.04 to scrape some code on webpage. After making a virtualenv directory, while activating virtualenv using
source bin/activate,
I installed selenium, headless firefox, pyvirtualdisplay and firefox geckodriver.
I installed headless firefox according to here.
And I also Found out that there are different python2.7 folders at
"/usr/lib/python2.7/" and "~/ladder_selenium/lib/python2.7" (ladder_selenium is the Virtualenv directory)
and after I ran a python code which contains
from selenium import webdriver
, the error below happens.
Traceback (most recent call last):
File "predict.py", line 12, in <module>
driver = webdriver.Firefox()
File "/home/heyjude/ladder_selenium/local/lib/python2.7/site-packages/selenium/webdriver/f
self.service.start()
File "/home/heyjude/ladder_selenium/local/lib/python2.7/site-packages/selenium/webdriver/c
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
Could you tell me what to fix?
EDIT for the COMMENT BELOW:
(ladder_selenium) heyjude#ladder-selenium:~$ export DISPLAY=:99
(ladder_selenium) heyjude#ladder-selenium:~$ firefox
XPCOMGlueLoad error for file /opt/firefox/libmozgtk.so:
libgtk-3.so.0: cannot open shared object file: No such file or directory
Couldn't load XPCOM.

python - control the browser with selenium module

I installed python version 3.5.2, selenium version 3.0.1 and firefox version 49.0.2.
After all of that and in my shell scripting I typed
>>> from selenium import webdriver
>>> browser = webdriver.Firefox()
and got error as this below:
Could someone guide me on what is wrong here.
I appreciate it. I am just starting out on python. Thanks
#
Traceback (most recent call last):
File "C:\Users\D\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Users\D\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "C:\Users\D\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#1>", line 1, in <module>
browser = webdriver.Firefox()
File "C:\Users\D\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 135, in __init__
self.service.start()
File "C:\Users\D\AppData\Local\Programs\Python\Python35-32\lib\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.
#