So, I am using OS X El Capitan with Eclipse (Neo) and Python. I am wrote some Python with Selenium scripts.
These scripts were working fine.
Then I upgraded from OSX Sierra to El Capitan
Note: this is about the only major change
that I did to my setup.
When I tried to run the same scripts, now, I get the
Message: chromedriver executable needs to be in PATH
As far I can tell chromedriver IS on my PATH.
Now, I can only make my scripts work if I hard copy the path to my chrome driver, which is not the most elegant way to do things, as we all know.
Has anyone else has/had this issue? Thoughts on any configuration with my Eclipse + Python.
My Eclipse and Python project screen shot
my PYTHONPATH screen shot
I dont know about python. But the implementation for the webdriver should be same irrespective of the language. Here you have called the chrome webdriver, but have you defined the path for chromedriver.exe in you code? For example, in java it looks like this
System.setProperty("webdriver.chrome.driver", "C:\\selenium-java-3.4.0/chromedriver.exe");
driver = new ChromeDriver();
The error you are getting is referring to the chromedriver.exe not the python environment.
Python Solution from Google documentation:
import time
from selenium import webdriver
driver = webdriver.Chrome('/path/to/chromedriver') # Optional argument, if not specified will search path.
driver.get('http://www.google.com/xhtml');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
First of all verify your driver path , if you open a command prompt and type in chromedriver and hit Enter. If you get message "Starting ChromeDriver 2.15.322448 .." your path is correctly set up.
In python, alternate solution is you can use
driver = webdriver.Chrome("path_to_driver/chromedriver.exe")
Hope this should work !
Related
I am trying to open Firefox with this simple program in python, I am using the latest version of Ubuntu.
from selenium import webdriver
brow = webdriver.Firefox()
But I am getting the error message,
"selenium.common.exceptions.SessionNotCreatedException: Message: Failed to start browser /snap/firefox/current/firefox.launcher: no such file or directory"
I have tried updating firefox and using a different geckodriver.
The error is most likely a bug in GeckoDriver causing it to try to find Firefox inside Snap instead of the default location /usr/bin/firefox, because the script has been run from PyCharm that was installed through Snap.
To solve the issue, you have to unset the Snap environment variables before running the script. Actually, I found out that only two variables must be unset: SNAP_NAME and SNAP_INSTANCE_NAME:
$ unset SNAP_NAME
$ unset SNAP_INSTANCE_NAME
Surely you should take a good look at the paths you enter, however, i recommend a generic approach.
You can use a webdriver-manager that takes care of any problems in this respect automatically and in any supported operating system
from selenium import webdriver
from webdriver_manager.firefox import GeckoDriverManager
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
N.B.: this is compatible with Selenium 4.x and below.
It looks like after opening the browser, Selenium cannot move on for some reasons I can't figure out. No error was ever displayed.
Here is my simple code:
import selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# Using Chrome to access web
browser = webdriver.Chrome(executable_path = "C:\Program Files\Google\Chrome\Application\chrome.exe")
print ("done")
# Open YouTube website
browser.get("https://www.youtube.com/")
The browser opens just fine, but the print("done") statement is never executed. (In the terminal the word "done" was never printed. So, it infers that the selenium has never finished executing the command to open the browser even though the browser has opened, and I have waited for several minutes.
Thanks in advance to our wonderful StackOverflow community!
The reason is because you are using chrome.exe which is for browser. Instead you should download chromdriver.exe, Please download from here. You should download Latest stable release: ChromeDriver 94.0.4606.61 (as on 3rd-oct-2021). Keep that in your automation directory and any directory of your preference.
driver_path = r'C:\\Users\\username\\Desktop\\Automation\\chromedriver.exe'
driver = webdriver.Chrome(executable_path = driver_path)
Note that, in place of driver_path, you should give the path where you've kept the chromdriver.exe
You should use chromedriver.exe instead of the path to your chrome.exe.
Download the chromedriver suitable for your chrome version, from here:
donwload Chromedriver.exe
Afterwards, do something like this:
browser = webdriver.Chrome("E:\YourPathToChromeDriver\chromedriver.exe")
Try these steps:
Check your Google Chrome version here "chrome://settings/help"
Download chromedriver.exe from "https://chromedriver.chromium.org/downloads"
Change executable path to newly downloaded file.
As mentioned above, this issue is the chrome.exe. You need to use a chromedriver instead. You can download one manually here https://chromedriver.chromium.org/downloads and then set the path to it like you did to the chrome.exe.
However, instead of downloading the chromedriver manually, I recommend using a library on GitHub which does that for you and loads it from cache if there is already one installed. (I'm not the owner nor the maintainer of this repository, but I do find it rather simple to use.)
https://github.com/SergeyPirogov/webdriver_manager
First you'd need to pip install webdriver-manager and then you can use it as following:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
I am having trouble using Selenium Chromedriver on Windows 7. To display the problem, I've boiled it down to a simple script to simply launch the New York Times website:
from selenium import webdriver
# --LOCATIONS --
# The Chrome app:
# C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
# The Chrome binary:
# C:\Python27\Scripts\chromedriver.exe
chromedriver_path = "C:\Python27\Scripts\chromedriver.exe"
driver = webdriver.Chrome(executable_path=chromedriver_path)
driver.get('https://www.nytimes.com/')
The Chrome Browser launches (leading me to speculate that there's nothing with the Chrome application path), but rather than going to the NYT website, the following happens:
The string data:, appears in the URL address bar, and 2 alert notifications come up: one that says "You are using an unsupported command-line flag: --ignore-certificate-errors. Stability and security will suffer." and another that says "Disable developer mode extensions: Extensions running in developer mode can harm your computer. If you're not a developer, you should disable these extensions running in developer mode to stay safe."
This didn't happen when I used Selenium for Firefox- so I'm not sure what to do with Chrome. I've tried looking this issue up on the internet beforehand, but all the issues/solutions are dated from a few years back (2014-2015), and I believe the Selenium packages and Chromedriver binaries have been updated since then.
Does anyone know how I can get my code working? Thank you in advance.
I'd have to see your computer to examine how Chromedriver is installed, but as that's not quite feasible, I would at least recommend uninstalling any chromedriver executables on your computer and then downloading it into your project's directory.
It's really just an IT rule-of-thumb; if you've ruled out every other issue that you're aware of, then there's a good chance the problem is something you're not recognizing. Start at square 1 and reinstall Chromedriver.
You can disable Developer mode extension by following code(java)
ChromeOptions options = new ChromeOptions();
options.addArguments("chrome.switches","--disable-extensions");
System.setProperty("webdriver.chrome.driver","F:\\Stuff\\Jars\\chromedriver.exe");
driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.get("https://www.nytimes.com/");
I put the chromedriver in a random folder. And wish to call it to use webdriver from selenium
But actually on: https://code.google.com/p/selenium/wiki/ChromeDriver, says it expects the driver to be under: /usr/bin/google-chrome
I'm using dreamhost, and they told me I need to pay more to sudo /usr/bin folder. Anyway to walk around those? (namely, execute chromedriver from random location)
I tried the following (found from anther question about the same topic but no exact answer)
chromedriver = "path/to/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
browser = webdriver.Chrome(chromedriver)
But it doesn't work. It gave me error: cannot find Chrome binary
Seems like another problem:(
Thanks ahead, it's gonna be very helpful! Btw I'm using Python/Flask
You can pass chromedriver location using executable_path variable. Please find below sample code:
from selenium import webdriver
driver = webdriver.Chrome(executable_path="/path/to/chromedriver")
driver.get("https://code.google.com/p/chromedriver/issues/detail?id=1260")
You need to add the location of chrome driver to your PATH.
PATH=$PATH:[random folder path]
after that you should be able to run chromedriver and get something like:
Starting ChromeDriver 2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b) on port 9515
Only local connections are allowed.
I want to launch Internet Explorer (8) browser on Windows XP SP3 using selenium. I coded these lines:
from selenium import webdriver
class InternetExplorer8:
def ie8(self):
self.browser=webdriver.Ie()
self.browser.get("http://www.begueradj.com")
if __name__=='__main__':
IE=InternetExplorer8()
IE.ie8()
I got this error:
self.iedriver.start() File
"C:\Python34\lib\site-packages\selenium\webdriver\ie\service.py", line
73, in start and read up at
http://code.google.com/p/selenium/wiki/InternetExplorerDriver")
selenium.common.exceptions.WebDriverException: Message: 'IEDriver
executable needs to be available in the path. Please download from
http://selenium-release.storage.googleapis.com/index.html and read up
at http://code.google.com/p/selenium/wiki/InternetExplorerDriver
Note that I launch firefox without any problem using the same code, except internet explorer and crhome (that outputs a similar error). How could I resolve this problem ?
You need to download Internet Explorer driver and place the path to it into PATH environment variable.
Or, alternatively, provide an executable_path argument to webdriver.Ie():
self.browser = webdriver.Ie(executable_path='path\to\iedriver\driver.exe')