Define Chromedriver to be used in run time - selenium

With current changes in chromedriver, the executable is tightly coupled with a specific version. If the browser version is lower than the target version, it throws exception.
E.g. If we use Driver v.76, it will expect Chrome of version 76 only. For version 75, it will throw an exception.
Can I fetch the browser version before initializing the webdriver, so that I can finalize which chromedriver to be initialized, assuming, I have multiple driver executable supporting different versions of Chrome.
Thanks.

could you not get the local version from your machine and store in ENV variable:
MAC:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version
Windows:
wmic datafile where name="C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe" get Version /value
Linux:
google-chrome --version
and from here you define the driver version that is needed or point to an existing driver location.

Related

Selenium Headless : Do I need to install chrome to run test with chromedriver in headless mode [duplicate]

I've tried to search, but haven't found a definitive answer. On Windows Server 2016 WITHOUT Chrome Browser actually installed. I downloaded the correct "chromedriver.exe" and placed it in "D:\Apps\chromedriver.exe". I have added to my environment PATH the full path as "D:\Apps\chromedriver.exe".
When I attempt to start my Windows Service that utilizes the latest Selenium, I get the following error:
Exception occurred: Failed initializing web driver: Message: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.14393 x86_64)
Question: Do I have to actually install the full-blown browser in addition to the chromedriver, or is this simply just not finding the chromedriver.exe in my Python code (included below for full disclosure):
def __init__(self, username, password, environment='cert'):
self.username = username
self.password = password
self.environment = environment
# Instantiate a chrome options object so you can set the size and headless preference
self.chrome_options = Options()
# Toggle Headless or not
if HEADLESS_TOGGLE == 1:
self.chrome_options.add_argument("--headless")
self.chrome_options.add_argument("--disable-gpu") # Disables "Lost UI Shared Context GPU Error on Windows"
self.chrome_options.add_argument('--disable-extensions') # Disables Extensions
self.chrome_options.add_argument("--disable-software-rasterizer") # Disables "Lost UI Shared Context GPU Error on Windows"
self.chrome_options.add_argument("--window-size=1024x768")
self.chrome_options.add_argument("--log-level=3") # Errors Only
self.chrome_options.add_argument("--incognito") # Keeps history and logs clear
self.chrome_options.add_argument("--no-sandbox")
self.chrome_options.add_argument("--mute_audio") # No loud surprises!
self.chrome_options.add_argument("--no-gpu") # Disables gpu-based errors (headless)
self.driver = webdriver.Chrome(chrome_options=self.chrome_options)
This error message...
Exception occurred: Failed initializing web driver: Message: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.14393 x86_64)
...implies that the ChromeDriver was unable to find the Chrome binary while trying to initiate a new new Browsing Context i.e. Chrome Browser session.
As per the documentation with in the wiki page of ChromeDriver:
ChromeDriver is a standalone server which earlier implemented the WebDriver's wire protocol but slowly and gradually shifting it's implementation as per WebDriver standard.
The ChromeDriver consists of three separate pieces.
There is the browser itself i.e. chrome
The language bindings provided by the Selenium project i.e. the driver
An executable downloaded from the Chromium project which acts as a bridge between chrome and the driver which is called chromedriver and we refer to it as the server.
In generic scenarios the server expects you to have Chrome installed in the default location for each system:
Linux: /usr/bin/google-chrome 1
Mac: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome
Windows XP: %HOMEPATH%\Local Settings\Application Data\Google\Chrome\Application\chrome.exe
Windows Vista and newer: C:\Users\%USERNAME%\AppData\Local\Google\Chrome\Application\chrome.exe
Note: 1: For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.
You can find a detailed discussion on overriding the default Chrome binary location in WebDriverException: unknown error: cannot find Chrome binary error with Selenium in Python for older versions of Google Chrome
Solution
So ideally to execute your tests using ChromeDriver / Chrome combo you need to:
Install the full-blown google-chrome browser.
Download the compatible version of chromedriver.exe
Quick installation of ChromeDriver:
Mac users with Homebrew: brew tap homebrew/cask && brew cask install chromedriver
Debian based Linux distros: sudo apt-get install chromium-chromedriver
Windows users with Chocolatey installed: choco install chromedriver
You can find a couple of relevant discussions in:
How to work with a specific version of ChromeDriver while Chrome Browser gets updated automatically through Python selenium
Selenium for ChromeDriver and Chrome Browser and the log message “Only local connections are allowed”
WebDriverException: Message: Service /usr/lib/chromium-browser/chromedriver unexpectedly exited on Raspberry-Pi with ChromeDriver and Selenium
Reference
You can find a detailed discussion in:
WebDriverException: unknown error: cannot find Chrome binary error with Selenium in Python for older versions of Google Chrome
Users provided relevant link to confirm that, "YES" a full Chrome installation is needed in addition to the actual chromedriver.
Link: https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver
In my case, I am using PowerShell. I figured out that you need to put the correct chromedriver.exe version, according to the installed Chrome browser, in the path under Selenium Module installation folder, and replace the existing file.
Check this answer for details:
I cannot start chrome instant using PowerShell and Selenium module

Mismatch between CMD and selenium run

I am trying to run some classes via CMD with the command : mvn test
When I run it throw the eclipse with testng it's run well.
But when I am trying to run it from CMD I got this message :
session not created: This version of ChromeDriver only supports Chrome version 97
Current browser version is 99.0.4844.51
My chromedriver is :
C:\Program Files\Selenium\ChromeDriver>chromeDriver -v
ChromeDriver 99.0.4844.51
What is the problem ?
From where its take the sentence "This version of ChromeDriver only supports Chrome version 97" ?
How can I make it works please ?
You need to download ChromeDriver v99
Which you can find here
There can be a different version of the chrome driver (in your case version 97) present in the path or in the same folder.
Alternatively, you can pass the full path of chromedriver.exe when you are initializing the driver.
driver = webdriver.Chrome(executable_path=r'C:\Program Files\Selenium\ChromeDriver\chromedriver.exe')

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 80

when i go to command prompt and type chromedriver -v:
ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945#{#614})
but when i try to run this code :
from selenium import webdriver
class InstaBot:
def __init__(self):
self.driver=webdriver.Chrome()
self.driver.get("www.instagram.com")
InstaBot()
it gives me error like this:
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 80
why this is happening i tried to remove selenium as well as chromedriver
and reinstall of version 79.0.3945 but when i run it ,it show this can only be run on version 80
my chrome version is 79.0.3945 which is lastest ,and version 80 chrome is chrome beta
This error message...
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 80
...implies that the ChromeDriver v80.0 was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You mentioned about using chromedriver=79.0.3945.36 and the release notes of chromedriver=79.0 clearly mentions the following :
Supports Chrome v79
Presumably you are using chrome v79.0 browser.
So, it's quite evident your have chromedriver=80.0 present within your system which is also within the system PATH variable and is invoked while you:
self.driver=webdriver.Chrome()
Solution
There are two solutions:
Either you upgrade chrome to Chrome Version 80.0 level. (as per ChromeDriver v80.0 release notes)
Or you can override the default chromedriver v80.0 binary location with chromedriver v79.0 binary location as follows:
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://google.com/')
You can find a detailed discussion in Ubuntu: selenium.common.exceptions: session not created: This version of ChromeDriver only supports Chrome version 79
Additional Considerations
Ensure to:
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
Reference
You can find a relevant detailed discussion in:
How to work with a specific version of ChromeDriver while Chrome Browser gets updated automatically through Python selenium
Use Bonigarcia plugin in project. After that it will manage all driver by itself.It reads chrome version and instantiate driver accordingly.
for help follow my post :
https://www.linkedin.com/pulse/webdrivermanager-bonigarcia-rohan-ravi-yadav/
or original git link/post
https://github.com/bonigarcia/webdrivermanager
If any help required , Let me know

InvalidOperationException: session not created: This version of ChromeDriver only supports Chrome version 76 with ChromeDriver Selenium in AzureDevOPS

I have Ux Automation test project where in I am using the NuGet for Selenium.Chrome.WebDriver. The Agent in the release pipeline has below versions of chrome & WebDriver
Google Chrome
version:
75.0.3770.100
Selenium Web Drivers
Chrome Driver
version:
75.0.3770.90
Environment:
ChromeWebDriver: location of chromedriver.exe
I have tried check-in the project with 75 & 76 NuGet reference. However, I am getting below error in both cases.
System.InvalidOperationException: session not created: This version of ChromeDriver only supports Chrome version 76 (SessionNotCreated)
Which version it is complaining for?
This error message...
System.InvalidOperationException: session not created: This version of ChromeDriver only supports Chrome version 76 (SessionNotCreated)
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
Though you mentioned about using chromedriver=75.0.3770.90 there may be multiple instances of chromedriver being present in your system and the the version of the chromedriver which is effective in your tests is chromedriver=76.0
Release Notes of chromedriver=76.0 clearly mentions the following :
Supports Chrome version 76
Presumably you are using chrome= 75.0.
Release Notes of ChromeDriver v75.0 clearly mentions the following :
Supports Chrome 75
So there is a clear mismatch between the ChromeDriver v76.0 and the Chrome Browser v75.0
Solution
Ensure that:
Selenium is upgraded to current levels Version 3.141.59.
ChromeDriver is updated to current ChromeDriver v79.0.3945.36 level.
Chrome is updated to current Chrome Version 79.0 level. (as per ChromeDriver v79.0 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Take a System Reboot.
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
Reference
You can find a relevant detailed discussion in:
How to work with a specific version of ChromeDriver while Chrome Browser gets updated automatically through Python selenium

ERROR org.openqa.selenium.WebDriverException: unknown error: call function result missing 'value' using Java [duplicate]

I am getting the below error while sending keys.
Result Message:
System.InvalidOperationException : unknown error: call function result missing 'value'
(Session info: chrome=65.0.3325.146)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.14393 x86_64)
I have updated the chrome driver to 2.36 but still my code search for 2.33?
Any idea ?
I've gotten the same error, please download the last ChromeDriver version and/or update chrome browser version and it will be working fine :)
https://chromedriver.storage.googleapis.com/index.html?path=2.36/
After updating the Google Chrome browser to Version 65.0.3325.146 (Official Build) (64-bit), I'm also encountered with the same error
while sending values to the input field, here's the error message...
selenium.common.exceptions.WebDriverException: Message: unknown error: call function result missing 'value'
using Chromedriver 2.32 and Google Chrome 65.0
As I did some research on the same, I found a recent commit on Google chrome v65 changelogs which help me to resolve the issue.
Solution:
Update Google Chrome to latest stable version (in my case it's v65 on 9/mar/2018)
Download and configure latest chromedriver (v2.36).
For configuring chromedriver (on Ubuntu) follow these steps...
Extract the downloaded zip file.
Copy the extracted chromedriver file to /usr/local/bin or to the location where you usually store the executable binaries.
Add the same path (where you place the chromedriver file) to environment variable PATH as
export PATH=$PATH:/usr/local/bin
For testing the installation, restart the terminal and type this command
chromedriver --version
it would show the version of chromedriver that you just installed.
Note: If the chromedriver already installed and configured then just replace the existing driver file and If you don't know where the Chromedriver binaries already stored then try to find the file using following command
sudo find -H / -type f -iname chromedriver
It is because of the update of chrome browser version from 64.xx to 65.xx
Now you have 2 options to run your tests successfully.
Downgrade your chrome browser to previous version and with the old chromedriver which you have now.
Upgrade your Chromedriver to 2.36 version with the updated Chrome browser.
visit https://chromedriver.storage.googleapis.com/index.html?path=2.36 and download the new chromedriver.
Option 2 is better.
Replace your ChromeDriver.exe with latest version.. Same can be downloaded from Google easily.
Also its better to get it done automatically by using webDriver manager as explained below -
1. Add Mvn dependency to your project POM:
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>${webdrivermanager.version}</version>
<scope>test</scope>
</dependency>
Now in your Browser instantiation class instead of using traditional way to create driver i.e. by using System.setProperty(See belwo)...
System.setProperty("webdriver.chrome.driver","src/test/resources/drivers/chromedriver.exe");
Use below approach:
WebDriverManager.chromedriver().setup();
webDriver = new ChromeDriver(chromeOptions);
And that's all, you are done!
Use below links for your reference-
What is Browser Binary Manager how to use it for Selenium
or chkout git project for same-
https://github.com/bonigarcia/webdrivermanager#webdrivermanager-as-java-dependency
Need to update chromedriver :
In console, run: chromedriver-update 2.36
The error says it all :
System.InvalidOperationException : unknown error: call function result missing 'value'
(Session info: chrome=65.0.3325.146)
(Driver info: chromedriver=2.33.506120
The error clearly complains about InvalidOperationException
Your main issue is the version compatibility between the binaries you are using as follows :
You are using chromedriver=2.33
Release Notes of chromedriver=2.33 clearly mentions the following :
Supports Chrome v60-62
You are using chrome=65.0
Release Notes of ChromeDriver v2.37 clearly mentions the following :
Supports Chrome v64-66
Your Selenium Client version is unknown to us.
So there is a clear mismatch between the ChromeDriver version (v2.33) and the Chrome Browser version (v65.0)
Solution
Upgrade Selenium to current levels Version 3.11.0.
Upgrade ChromeDriver to ChromeDriver v2.37 level.
Keep Chrome version in between Chrome v64.x-66.x levels. (as per ChromeDriver v2.37 release notes)
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
Use CCleaner tool to wipe off all the OS chores before and after the execution of your test Suite.
If your base Web Browser/Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Browser/Web Client.
Execute your #Test.
If you are on Mac:
brew upgrade selenium-server-standalone
brew upgrade chromedriver
if the above two are not installed:
brew install selenium-server-standalone
brew install chromedriver
I'm running Protractor and have encountered the same issue.
The solution in my case was rather simple.
$ npm update protractor -g
$ webdriver-manager update
If you are on the latest stable Google Chrome (e.g. 67) I recommend to:
brew uninstall chromedriver
brew tap homebrew/cask
brew cask install chromedriver
These set of commands will uninstall your current chromedriver, check for updates and install the latest found (e.g. 2.40).
Use xpaths instead of class names to locate elements
After updating chrome and its drivers it didn't helped me at all!!
I don't know how much it makes sense but it worked for me when i replaced class name with xpath. This is the xpath , i used to automate sending whatsapp message using python.
driver.find_element_by_xpath('//*[#id="main"]/footer/div[1]/div[2]/div')
previously i Was Using
driver.find_element_by_class_name('Some class Name Here')
In my case the team I'm on points selenium to a specific chromedriver file we had. In order to get Selenium to use the updated chromedriver, I first installed it with brew and then created a symbolic link to point where Selenium looks for it:
brew install chromedriver
ln -s /usr/local/Cellar/chromedriver/2.36/bin/chromedriver /path/where/selenium/expects/chromedriver
On the chance this might be helpful to someone I needed an additional step:
I am on MacOS X. I did
brew upgrade chromedriver
bundle exec chromedriver-upgrade
I have the chromedriver-helper gem installed, but it is stashed and requires the "bundle exec" prefix or the shell can't find the command.
The above fixed my problem.
As mentioned by others, the latest chromedriver did the trick for me. In case you downloaded the driver manually and want to tell appium to use the new chromedriver you can do so by this command:
appium --chromedriver-executable /path/to/driver/chromedriver ....
I'm running Protractor (webdriver-manager) with Selenium in a Windows environment, and I had to do the following:
webdriver-manager update --versions.chrome="2.36" (This downloaded the new Chromedriver to the right path but didn't enable it in protractor.)
Edit %userprofile%\AppData\Roaming\npm\node_modules\protractor\config.json and changed the chromedriver value from 2.32 to 2.36.
Delete my old chromedriver_2.32.exe from %userprofile%\AppData\Roaming\npm\node_modules\protractor\selenium for good measure (not sure if that was required.)
Or:
When another Chromedriver update became needed, I was no longer able to update this way. A configuration setting still expected the old path and filename, and I couldn't figure out where to change that setting. So I just renamed the latest chromedriver to "chromedriver.exe" and stuck it in C:\Windows\system32 (which is always referenced by PATH). Crude, but effective.
If you're using gulp-protractor plugin, make sure to update it as well.
I don't know if you're still on this, but I was receiving a similar error. I had the latest version of chromedriver in my PATH and Google Chrome was updated. I run Python 3.6 on windows 10 x64 bit. What I was getting trying to select a value from a dropdown menu on a webpage. The weird thing was, it would select the dropdown value correctly and the page would be updated nicely, but I'd receive that stupid error anyway and my script would freeze. So I just made an exception error handler for it, because like I said it selected the dropdown value correctly, so I just wanted to bypass that dumb error message:
# select by value
try:
select.select_by_value('100')
except:
pass
hopefully someone finds this helpful.
The issue is because of mismatch in chromedriver and chrome browser version.
Below link specifies the versions of chromedriver supporting the chrome browser's version.
http://chromedriver.chromium.org/downloads