chrome driver is not working in windows - python

I want to run my python selenium scripts in chrome browser on windows. I downloaded chrome driver and placed the exe file in "C:\Python27\Scripts" but still I'm getting error as
Traceback (most recent call last):
File "C:\Users\INNOVATE\Desktop\workspace\Sample\sample.py", line 3, in <module>
driver = webdriver.Chrome()
File "C:\Python27\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\chrome\webdriver.py", line 59, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\chrome\service.py", line 66, in start
"ChromeDriver executable needs to be available in the path. "
selenium.common.exceptions.WebDriverException: Message: ChromeDriver executable needs to be available in the path. Please download from http://chromedriver.storage.googleapis.com/index.html and read up at http://code.google.com/p/selenium/wiki/ChromeDriver
what should I do?

try this package.
from selenium import webdriver
import chromedriver_autoinstaller
chromedriver_autoinstaller.install()
#maximize the chrome
chrome_options = Options()
chrome_options.add_argument("--start-maximized")
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://www.google.com")
you can defiantly remove chrome_options or add more arguments.
Please see the documentation, https://pypi.org/project/chromedriver-autoinstaller/

Please make sure you have performed all the required steps to open Chrome using Selenium.
Step1: Download Chrome Driver
Latest Release of Chrome Driver you can found is ChromeDriver 2.13.
Please use Link Chrome Driver to get the latest one.
Step2: Save the Chrome Driver to your Project Location and give the path of that folder in your code.
In my case i have saved the Chrome Driver in 'S' drive.
System.setProperty("webdriver.chrome.driver","S://Chrome Driver//chromedriver.exe");
Please check the path again where i believe is the problem in your code.

Related

FileNotFoundError: [WinError 3] The system cannot find the path specified:...chromedriver.exe

I am trying to use selenium for my project when I run my python file which contains the following codes , I get an error written just below the file code.
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://google.com')
**
[WDM] - Current google-chrome version is 85.0.4183 [WDM] - Get LATEST
driver version for 85.0.4183 [WDM] - Driver
[C:\Users\AHG.wdm\drivers\chromedriver\win32\85.0.4183.87\chromedriver.exe]
found in cache Traceback (most recent call last): File "newWeb.py",
line 9, in
driver = webdriver.Chrome(ChromeDriverManager().install()) File "C:\Anaconda3\envs\ppp_web\lib\site-packages\webdriver_manager\chrome.py",
line 34, in install
os.chmod(driver_path, 0o755) FileNotFoundError: [WinError 3] The system cannot find the path specified:
'C:\Users\ppp\.wdm\drivers\chromedriver\win32\85.0.4183.87\chromedriver.exe'
**
could anyone help me how to solve this issue.
I had the same problem once. I have to download the ChromeDriver and connect it to an absolute path.
driver = webdriver.Chrome(r "C:\Users\Normal\Desktop\WebCrawler\chromedriver_win32\chromedriver.exe")
You can download the driver from the web. For example: https://chromedriver.chromium.org/downloads
I have had the same issue
in my issue, I solved when ı delete drivers.json and drivers file inside of "C:\Users\ppp\.wdm"
installed drivers have inside of drivers.json .but sometimes something can delete driver but not delete inside of drivers.json
ChromeDriverManager().install() opens drivers.json file. and that gets the last installed chrome driver path from the driver.json. the driver uses from there if it is the last version. when the driver uses from this path but there is no file. it causes this problem

This version of ChromeDriver only supports Chrome version 79 - Python

This error drives me crazy. My code is:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import chromedriver_binary
from selenium.webdriver.common.by import By
import time
from influxdb import InfluxDBClient
chrome_options = Options()
chrome_options.add_argument("--headless")
chromedriver_binary =
"/home/dario/scripts/cron_run/web_app_login_checker/chromedriver/chromedriver"
driver = webdriver.Chrome(chromedriver_binary, options=chrome_options)
If I do:
./chromedriver -v
ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-
heads/3945#{#614})
It's the right version.
Full traceback is:
Traceback (most recent call last):
File "grafana.py", line 12, in <module>
driver = webdriver.Chrome(chromedriver_binary, options=chrome_options)
File
"/home/dario/scripts/cron_run/web_app_login_checker/lib/python3.6/site-
packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File
"/home/dario/scripts/cron_run/web_app_login_checker/lib/python3.6/site-
packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File
"/home/dario/scripts/cron_run/web_app_login_checker/lib/python3.6/site-
packages/selenium/webdriver/remote/webdriver.py", line 252, in
start_session
response = self.execute(Command.NEW_SESSION, parameters)
File
"/home/dario/scripts/cron_run/web_app_login_checker/lib/python3.6/site-
packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File
"/home/dario/scripts/cron_run/web_app_login_checker/lib/python3.6/site-
packages/selenium/webdriver/remote/errorhandler.py", line 242, in
check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session
not created: This version of ChromeDriver only supports Chrome version
79
None of the already discussed topics here on Stack Overflow helped me.
The problem is the Chrome browser version, not the ChromeDriver version. You need to update it to version 79, or downgrade the ChromeDriver. You can find here the matching versions.
If you are getting this error when you run stuffs on automated cluster and you are downloading the stable version of the google chrome every time then you can use the below shell script to download the compatible version of the chrome driver dynamically every time even if the stable version of the chrome gets updated. You could do something similar to this python to make it work.
%sh
#downloading compatible chrome driver version
#getting the current chrome browser version
**chromeVersion=$(google-chrome --product-version)**
#getting the major version value from the full version
**chromeMajorVersion=${chromeVersion%%.*}**
# setting the base url for getting the release url for the chrome driver
**baseDriverLatestReleaseURL=https://chromedriver.storage.googleapis.com/LATEST_RELEASE_**
#creating the latest release driver url based on the major version of the chrome
**latestDriverReleaseURL=$baseDriverLatestReleaseURL$chromeMajorVersion**
**echo $latestDriverReleaseURL**
#file name of the file that gets downloaded which would contain the full version of the chrome driver to download
**latestDriverVersionFileName="LATEST_RELEASE_"$chromeMajorVersion**
#downloading the file that would contain the full release version compatible with the major release of the chrome browser version
**wget $latestDriverReleaseURL**
#reading the file to get the version of the chrome driver that we should download
**latestFullDriverVersion=$(cat $latestDriverVersionFileName)**
**echo $latestFullDriverVersion**
#creating the final URL by passing the compatible version of the chrome driver that we should download
**finalURL="https://chromedriver.storage.googleapis.com/"$latestFullDriverVersion"/chromedriver_linux64.zip"**
**echo $finalURL**
**wget $finalURL**
I was able to get the compatible version of chrome browser and chrome driver using the above approach when running scheduled job on the databricks environment and it worked like a charm without any issues.
Hope it helps others in one way or other.
Check your chrome version
Download the same version of the chrome driver
Check the latest driver here
Update your driver in the reference folder.
In my case, I am using the windows 10 and python I've updated with the latest chromedriver.exe file (for Chrome v83)
This error message...
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 79
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser v79.x session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using chromedriver=79.0.3945.36
Release Notes of chromedriver=79.0.3945.36 clearly mentions the following :
Supports Chrome version 79
Presumably you are using the latest Version 78.0.3904.108 (Official Build)
So there is a clear mismatch between the ChromeDriver v79.0.3945.36 and Chrome Browser v78.0.3904.108
Solution
There are two possible solutions:
Either you need to downgrade ChromeDriver to ChromeDriver 78.0.3904.105
Download, install and use Chrome from the Chrome Release Channels
Linux Stable channel
Linux Beta channel
Linux Development channel
latest build

How to setup Selenium with headless Firefox on Raspbian Buster

I have gotten this to work in Jessie/Stretch with previous Firefox versions but can't seem to get it to work with Raspberry Pi 3B or 4 running Raspbian Buster and the latest Selenium, 3.141.0 in Python.
Since iceweasel is no longer available I install firefox-esr via apt and get the latest ARM geckodriver, which is currently 0.23.0, from https://github.com/mozilla/geckodriver/releases then run the code below:
from selenium import webdriver
from pyvirtualdisplay import Display
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
capabilities = webdriver.DesiredCapabilities().FIREFOX
capabilities["marionette"] = False
driver = webdriver.Firefox(options=options, executable_path='/usr/bin/geckodriver', capabilities=capabilities)
driver.get('https://www.google.com')
print(driver.page_source)
driver.close()
display.stop()
This returns the error:
Message: Can't load the profile. Possible firefox version mismatch. You must use GeckoDriver instead for Firefox 48+. Profile Dir: /tmp/tmpxMUUcF If you specified a log_file in the FirefoxBinary constructor, check it for details.
Traceback (most recent call last):
File "SeleniumDebugExample.py", line 50, in <module>
driver = webdriver.Firefox(options=options, executable_path='/srv/main/geckodriver', capabilities=capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 191, in __init__
self.binary, timeout)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 52, in __init__
self.binary.launch_browser(self.profile, timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 73, in launch_browser
self._wait_until_connectable(timeout=timeout)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 114, in _wait_until_connectable
% (self.profile.path))
WebDriverException: Message: Can't load the profile. Possible firefox version mismatch. You must use GeckoDriver instead for Firefox 48+. Profile Dir: /tmp/tmpxMUUcF If you specified a log_file in the FirefoxBinary constructor, check it for details.
I am specifying geckodriver though so I am not sure what the issue is...
If anyone has gotten headless selenium to work on Raspbian Buster and can share some could it would be greatly appreciated!
After a bunch of testing it seems the issue was with adding the marrionette=False capability... Back in Jessie with iceweasel I had needed to add that for it to work but it seems with firefox-esr that is no longer necessary... I was able to get this working with just the below:
from selenium import webdriver
from pyvirtualdisplay import Display
driver = webdriver.Firefox(executable_path='/usr/bin/geckodriver')
driver.get('https://www.google.com')
print(driver.page_source)
driver.close()
display.stop()

How to launch Chrome in Selenium correctly

I can not launch Chrome in Selenium.
driver=webdriver.Chrome()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/anaconda/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 67, in __init__
desired_capabilities=desired_capabilities)
File "/usr/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 87, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 141, in start_session
'desiredCapabilities': desired_capabilities,
File "/usr/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 201, in execute
self.error_handler.check_response(response)
File "/usr/anaconda/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 181, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(Driver info: chromedriver=2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4),platform=Linux 3.19.8-100.fc20.x86_64 x86_64)
I use "chromedriver_linux64.zip 2017-10-03 21:09:52 3.90MB" from
url.
You are using the current latest chromedriver 2.33 with Google Chrome 38.0.2125.104.
From the release notes, the support for this version is:
----------ChromeDriver v2.33 (2017-10-03)----------
Supports Chrome v60-62
Make sure also that you are using the latest stable version of selenium.
Furthermore, from Help WebDriver find the downloaded ChromeDriver executable, you should do one of these
include the ChromeDriver location in your PATH environment variable
(Python only) include the path to ChromeDriver when instantiating webdriver.Chrome (see sample below)
If you're going to use an old version of Chrome - you will need to match the version of chromedriver to it. In your case you are using Chrome 38, which was last officially supported by ChromeDriver 2.13, which you can find here
If your users are using newer versions of Chrome, I would recommend updating your distro and installed chrome to match them.
The error says it all :
File "<stdin>", line 1, in <module>
Seems the error occurs on the very first line which is as :
driver=webdriver.Chrome()
This is because here in this code block unless you import webdriver, the driver object is unable to properly initiate/handle the instance of WebBrowser i.e. Chrome Browser.
Solution :
While working with Selenium 3.x, ChromeDriver 2.33.x you need Chrome Browser v60-62 with Python 3.x bindings, and you have to do the following:
Download the chromedriver binary from this link.
Import the necessary modules
Provide the absolute path of the chromedriver binary in your system.
Below is the minimal code :
//The Linux Example
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'/usr/bin/chromedriver')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()
//The Windows Example
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()
Update :
On a separate note as you are seeing WebDriverException: Message: unknown error: Chrome failed to start: crashed perform the following additional steps :
Uninstall Google Chrome from your system through Revo Uninstaller.
Run CCleaner to wipe out all the unwanted OS chores.
Take a system Reboot
Install latest official build of Google Chrome
Execute your Test.
import the selenium and chrome.option to let chrom run in headlessmode
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
if you use chrome or chromiun as root user on linux you should add "--no-sandbox" option and set windows size to avoid some item no show because the window size is too small
chrome_options = Options()
chrome_options.add_argument("--headless") # headless mode
chrome_options.add_argument("--no-sandbox") # run as root user should add --no-sandbox option
chrome_options.add_argument("--window-size=1920x1080")
you can download the chrome driver from http://chromedriver.storage.googleapis.com the last version is 2.38
chrome_driver = "path to chromedriver"
# start the driver
driver = webdriver.Chrome(chrome_options=chrome_options, executable_path=chrome_driver)
driver.get("https://www.google.com")

Firefox driver can't start for Selenium 3.0.1 with FF49 and Python

i have following Selenium Webdriver script with Python. But i got error:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True
driver = webdriver.Firefox(capabilities=caps)
driver.get("http://www.mahsumakbas.net")
print driver.title
driver.close()
error is:
Traceback (most recent call last): File
"C:\Mahsum\DevelopmentWorkSpace\Eclipse\Java\selenium_proj\src\hello.py",
line 6, in
driver = webdriver.Firefox(capabilities=caps) File "C:\Python27\lib\site-packages\selenium\webdriver\firefox\webdriver.py",
line 135, in init
self.service.start() File "C:\Python27\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.
Exception AttributeError: "'Service' object has no attribute
'process'" in >
ignored
Selenium Webdriver version is: 3.0.1
Firefox: 49.0.2
geckodriver: v0.11.1-win64
i added geckodriver path to Windows PATH variable.
where is the problem?
You can place the 'geckodriver' .exe in the base path of Python and it will work.
Alternatively, you have to declare the path to geckodriver when initializing if you prefer to have a clean Python folder. Either do it every time you run your script or by PATH as you says you've done. As Naveen suggests, a reboot is necessary before a PATH is correctly saved. You could also try to run this in the Windows command line:
setx path "%path%;c:\path\to\geckodriver-folder"
final code is like follow and working:
binary = FirefoxBinary("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe")
driver = webdriver.Firefox(firefox_binary=binary)
set path of geckodriver.exe without file name(only folder that it is placed) to PATH vairable.
this time, i have another problem:
driver.close() doesn't close firefox.
when change as driver.quit() it closes but following line is appear on console:
'NoneType' object has no attribute 'path'
there is not any indicator to show it is warning or error. Just line itself.
Try to add firefox profile
profile = webdriver.FirefoxProfile()
webdriver.Firefox(capabilities=caps,firefox_profile=profile)
from selenium import webdriver
# To Run on FireFox Browser
self.driver = webdriver.Firefox(executable_path="C:/Drivers/geckodriver.exe")
driver.get("http://www.mahsumakbas.net")
print(driver.title)
driver.close()

Categories