WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. - selenium - linux

Before you let me know that this is a duplicate, the issue I am facing is that I am running my python code using a jupyter-notebook via an Ubuntu subsystem on Windows.
I have made sure that the path to the folder on Windows where chromedriver is located is correct. However, I am still getting the same error. Further, I am unable to see where my files from the Ubuntu subsystem are (ie, I can't find a folder on Windows with those files).
Anyway in which I can correct this? such as editing the ~/.bashrc file on Ubuntu?
browser = webdriver.Chrome("C:/Users/vr235/Downloads/chromedriver/chromedriver.exe")
Error:
WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
EDIT:
While a solution was pointed by user DebanjanB and marked as duplicate, I tried the user's suggestion but got the same error.
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
browser = webdriver.Chrome(chrome_options=chrome_options, executable_path=r'C:\Users\vr235\Downloads\chromedriver\chromedriver.exe')
browser.get("https://www.sciencedirect.com/")
Error:
WebDriverException: Message: 'C:\Users\vr235\Downloads\chromedriver\chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

In case one is using a WSL, one can identify the path where the Chromedriver is present by viewing the mnt folder on WSL.
For instance: My chromedriver path was in the Downloads folder in C:/ drive
Path : /mnt/c/vr235/Users/Downloads/chromedriver.exe
Once you add the same, the above lines of code work perfectly.

Related

Linux, selenium can't find firefox binary from within a virtual environment

I'm running Pycharm and attempting to use selenium to launch and control an instance of firefox.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.binary_location = "/usr/lib/firefox/firefox"
browser = webdriver.Firefox(options=options)
This produces an error:
selenium.common.exceptions.InvalidArgumentException: Message: binary is not a Firefox executable
Am I writing the path of the firefox binary correctly? From the terminal within the virtual environment, there is no firefox directory in /usr/lib - presumeably because I'm in the virtual environment? From the system terminal, I can find it no problem at /usr/lib/firefox/firefox.
How do I write a path to the firefox executable in the system environment, from within my virtual environment in pycharm? What's happening here that's preventing me from seeing / accessing the system environment?
I've tried the instructions at each of the below, the issue is not that I need to set an option to the correct path - the binary is located in my system at /usr/lib/firefox/firefox - but setting the option as in the code above does not result in success, maybe because firefox does not exist at that location within the virtual environment.
I've tried all suggestions at each of the below:
Unable to open firefox using selenium-python-geckodriver
SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary'
Selenium on PyCharm cannot find firefox binary
Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided using GeckoDriver

Scrapy shell view(response) not working properly

When I open the Scrapy shell through the command scrapy shell "http://quotes.toscrape.com/" (this example comes from the Scrapy tutorial), I enter the command view(response) which opens my navigator (Firefox to be precise) with a path looking like file:///tmp/tmpnzkkilst.html and the error "File not found".
Any idea on how to solve this issue ?
It's not a scrapy but the firefox issue. I experienced the same. Files existed in my /tmp folder, however firefox was unable to open them. In my case the firefox was installed from snap by default and for some reason it could not open the files in /tmp.
Resolved it by downloading and installing the firefox directly from Mozilla's website and replacing the snap one.

How can I fix this geckodriver error in Python?

I started learning selenium, and when I ran this code...
from selenium import webdriver
browser = webdriver.Firefox()
print(type(browser))
When I ran that code, I got this error - Message: 'geckodriver' executable needs to be in PATH.
How can I fix this error? I'm working on Firefox 64bit, and my Selenium Version is '3.141.0'.
gekodriver is detected in the 3 following ways.
1. Using environment variable PATH
Add the absolute path to the gekodriver directory into the environmental variable PATH.
export PATH=PATH:/ABSOLUTE/PATH/TO/PARENT_DIRECTORY_OF/gekodriver
2. Current directory
Keep the gekodriver executable in the current directory where the Python script is being executed from.
3. Passed as executable_path
For example,
webdriver.Firefox(executable_path="c:\\gekodriver.exe")
The error is fixed, I just put the geckodriver.exe into the Python39 folder and it works now perfectly!

Selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary

I am trying to automate some stuff I do day-to-day online and get some experience in webscraping. I saw some stuff about Selenium and Python being good for beginners and thought I would give it a try. I ended up getting a simple script to work on my home computer but it doesn't find the Chrome binary at the path I am giving and I do not know what to do.
I used this to set my PATH environment variable to the directory that holds my chromedriver https://youtu.be/dz59GsdvUF8
I downloaded ChromeDriver 74.0.3729.6 (latest stable release) from https://sites.google.com/a/chromium.org/chromedriver/
I am using python3, visual studio code, and Ubuntu if any of that matters.
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
#Stack overflow said to try this but could not make it work
#opts = webdriver.ChromeOptions()
#opts.binary_location = "C:\webdrivers\chromedriver.exe"
#browser = webdriver.Chrome(chrome_options=opts)
#this is where my chrome is
#C:\Users\tucker.steven2\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Virtual Programs\Google Chrome\Chrome v62
#I have a chromedriver in the same directory as my python code
browser = webdriver.Chrome('chromedriver.exe')
browser.get(https://www.something.com/) #just a generic site
browser.quit()
My expected result is to open a chrome window to Hulu's website, the error I get is:
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729#{#29}),platform=Windows NT 10.0.16299 x86_64)
If you are on Ubuntu, which is a distribution of Linux, then your path is all wrong. The YouTube video was for Windows. The file structure is completely different on Linux. Please update with your current operating system where you are trying to run this. Also you don't need to write a script - just to open hulu. You can just make a shortcut and put it on your desktop. If you are trying to do something more complicated that takes a long time to do, that would be a better use case for making a selenium script. I get that you are trying to learn this, which is commendable. If you are really on Ubuntu as your operating system, then you would have a /usr/bin folder where your programs are. If you are running Windows, it would be C:\Users\"Your User Name Goes Here"\Documents or where ever you were going.
Programs would be in C:\Program Files\ or C:\Program Files(x86). I would recommend watching some YouTube videos about the path on your operating system.
The answer depends on your operating system and where you have saved your programs.

How to add Chromedriver to PATH in linux?

Trying to use Selenium with Chrome in a python script.
I get the following error:
WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
I know the location of the chromedriver executable.
How do I add it to the PATH?
thank you
You can specify the absolute path to your chrome driver in your script as such:
from selenium import webdriver
driver = webdriver.Chrome(executable_path='/path/to/driver/chromedriver')
Or you can add the path to your webdriver in the PATH system variable as so:
export PATH=$PATH:/path/to/driver/chrome-driver
You may add the above line to your /home/<user>/.profile file to make it permanent.
Tested on Ubuntu 17.10 running Python 2.7.14
Hope this helps!
The solution posted by #AnythingIsFine is indeed correct.
However in my case my pytest was still unable to find the chromedriver (despite it was correctly added to the PATH and from the terminal I could execute it).
So I've solved by adding an alias of the chromedriver in the /usr/bin directory:
sudo ln -s /path/to/chromedriver /usr/bin
Move Chromedriver to path with:
sudo mv -f ~/chromedriver /usr/local/bin/chromedriver
/usr/local/bin/chromedriver is path.
For selenium framework (python or java), Browser driver(chrome/firefox/ etc.) should be saved on the Path " /usr/local/bin/chromedriver & /usr/bin/chromedriver"
For Chrome Driver Link : https://chromedriver.chromium.org/downloads
go to the link and download the chrome driver for corresponding OS.
Linux:
Open the terminal on the Saved/downloaded directory then enter the command
"sudo mv /path/to/chromedriver /usr/bin"
"sudo mv /path/to/chromedriver /usr/local/bin"

Resources