SessionNotCreatedException only support Chrome version 80 - python

I have this code below and it throw the SessionNotCreatedException on the last line.
chrome_options = Options()
LANG = 'fr,fr_FR'
chrome_options.add_experimental_option('prefs', {'intl.accept_languages': LANG})
chrome_options.add_argument("--user-data-dir=chrome-data")
browser = webdriver.Chrome(options=chrome_options)
SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version 80
However, I am already using version 80 ! Downloaded here : https://chromedriver.storage.googleapis.com/index.html?path=80.0.3987.106/

Alternative which worked : SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81
However, the silent log mode doesn't work...
os.environ['WDM_LOG_LEVEL'] = '0'

Related

DeprecationWarning: headless property is deprecated, instead use add_argument('--headless') or add_argument('--headless=new') on Selenium 4.8.0 Python

I am trying to execute a basic program using Selenium 4.8.0 Python clients in headless mode:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
options = Options()
options.headless = True
s = Service('C:\\BrowserDrivers\\chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)
driver.get('https://www.google.com/')
driver.quit()
With the following configuration:
Selenium 4.8.0 Python
Chrome _Version 109.0.5414.120 (Official Build) (64-bit)
ChromeDriver 109.0.5414.25
Though the program gets executed successfully there seems to a DeprecationWarning as:
DeprecationWarning: headless property is deprecated, instead use add_argument('--headless') or add_argument('--headless=new')
Can anyone explain the DeprecationWarning and the required changes?
The deprecation of the headless property was announced in the Selenium Blog post Headless is Going Away! (archive) on January 29, 2023. The summary and suggested changes are as follows:
Headless is Going Away!
Headless is an execution mode for Firefox and Chromium based browsers. It allows users to run automated scripts in headless mode, meaning that the browser window wouldn’t be visible. In most of Selenium’s bindings there is a convenience method to set this execution mode while setting the browser options. However, Selenium 4.8.0 will be deprecated [sic] this method and now users need to set it through arguments when setting the browser options.
[...]
How can I set headless mode from now on?
In short, users can add the headless mode they want to use through arguments in browser options.
Before
options = ChromeOptions()
options.headless = True
driver = webdriver.Chrome(options=options)
driver.get('http://selenium.dev')
driver.quit()
After
options = ChromeOptions()
options.add_argument("--headless=new")
driver = webdriver.Chrome(options=options)
driver.get('http://selenium.dev')
driver.quit()
See the full blog post for additional background on why this change was implemented.
Test Automation developers had been using Headless Chrome and Firefox Headless for quite sometime now to execute the automated scripts in headless mode where the browser window wouldn't be visible. This was the traditional headless mode which now turns the old Headless mode.
The snippets being used were:
Java:
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
WebDriver driver = new ChromeDriver(options);
driver.get("https://selenium.dev");
driver.quit();
Python:
options = ChromeOptions()
options.headless = True
driver = webdriver.Chrome(options=options)
driver.get('http://selenium.dev')
driver.quit()
Javascript:
let driver = await env
.builder()
.setChromeOptions(new chrome.Options().headless())
.build();
await driver.get('https://selenium.dev');
await driver.quit();
According to this Selenium Blog this old headless mode will be still available by using the --headless switch with no value or with old value. This convenient yet deprecated method will be removed in Selenium 4.10.0
Renaming NativeHeadlessChrome to new Headless
Recently Chromium team have released the Native Headless mode which is now officially called the new Headless mode. This functionality have landed with:
Chromium v109.0.5400.0
ChromeDriver v109.0.5414.25
aptly supported through:
Selenium v4.8.0
The new syntax requires --headless=new to be passed as an argument, where as we passed only --headless while using Chrome since v96 till v108.
Sample Code snippets:
Java:
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless=new");
WebDriver driver = new ChromeDriver(options);
driver.get("https://selenium.dev);
driver.quit();
Python:
options = ChromeOptions()
options.add_argument("--headless=new")
driver = webdriver.Chrome(options=options)
driver.get('http://selenium.dev')
driver.quit()
Javascript:
let driver = await env
.builder()
.setChromeOptions(options.addArguments('--headless=new'))
.build();
await driver.get('https://selenium.dev');
await driver.quit();
CSharp:
var options = new ChromeOptions();
options.AddArgument("--headless=new");
var driver = new ChromeDriver(options);
driver.Navigate().GoToUrl("https://selenium.dev");
driver.Quit();
Ruby:
options = Selenium::WebDriver::Options.chrome(args: ['--headless=new'])
driver = Selenium::WebDriver.for :chrome, options: options
driver.get('https://selenium.dev')
driver.quit

Headless chrome authentication and ssl error in linux

I am trying to access to our internal company site to pull screenshot of it using headless chrome on redhat linux.
For this I am using Python, Selenium, Poppler and Chromedriver.
It is working perfectly on Windows, however on non-gui linux without options.add_argument('--ignore-certificate-errors') its returning white blank page but with ('ignore-certificate-errors') option added its giving 401 error.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome ()
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true)
WebDriver driver = new ChromeDriver (handlSSLErr);
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(executable_path=os.path.join(FLASK_STATIC_FOLDER,'chromedriver'),options=options)
URL = '"our internal webpage/"%s' %int(facemapperid)
driver.get(URL)
If you have any suggestions
The option to ignore certificate error is
options.add_argument('--ignore-certificate-errors')
You missed to add --
I was able to achieve what I wanted by doing below
First I made connection to let it cache my cookie
driver.get("https://username:password#mywebsite")
and then do it again
URL = 'username:password#mywebsite

Unable to launch Opera using Python Selenium

I am trying to launch opera using python selenium libraries. But getting capabilities error.
Codes I have tried:
Code1:
driver = webdriver.Opera()
driver.get('https://www.google.com')
Code2:
driver = webdriver.Opera(r'path to operadriver.exe')
driver.get('https://www.google.com')
Code3:
options = Options()
options.binary_location = r'C:\Opera\launcher.exe'
driver = webdriver.Opera(options=options)
driver.get('https://www.google.com')
Output:
Code1:
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary
Code2:
selenium.common.exceptions.WebDriverException: Message: Desired Capabilities must be a dictionary
Code3:
[20904:3220:0120/034255.122:ERROR:os_crypt_win.cc(61)] Failed to decrypt: The parameter is incorrect. (0x57)
DevTools listening on ws://127.0.0.1:59016/devtools/browser/0bb7bc3c-4b9a-451a-a736-a02a63feba7a
[20904:3220:0120/034255.673:ERROR:CONSOLE(0)] "Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.", source: chrome://startpage/ (0)
[20904:3220:0120/034255.674:ERROR:CONSOLE(0)] "Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.", source: chrome://startpage/ (0)
[20904:3220:0120/034255.675:ERROR:CONSOLE(0)] "Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.", source: chrome://startpage/ (0)
Only with code 3 the Opera browser launchers. But URL doesn't opens.
As I am able to launch chrome with similar codes.
This error message...
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Opera binary
and this error message...
selenium.common.exceptions.WebDriverException: Message: Desired Capabilities must be a dictionary
and this error message...
[20904:3220:0120/034255.122:ERROR:os_crypt_win.cc(61)] Failed to decrypt: The parameter is incorrect. (0x57)
...implies that the OperaDriver was unable to initiate/spawn a new Browsing Context i.e. Opera Browser session.
Solution
First of all you need to ensure that, you have downloaded the latest OperaChromiumDriver from operasoftware / operachromiumdriver. As per OperaDriver for Chromium-based Opera releases:
OperaChromiumDriver is a WebDriver implementation derived from ChromeDriver and adapted by Opera that enables programmatic automation of Chromium-based Opera products for desktop and Android platforms. It is a part of the Selenium project.
OperaChromiumDriver can be used without extra setup on Chromium-based versions of Opera starting from version 26.
Use both the arguments:
binary_location for opera binary and
executable_path for operadriver binary
Code Block:
from selenium import webdriver
from selenium.webdriver.opera.options import Options
options = Options()
options.binary_location = r'C:\Opera\launcher.exe'
driver = webdriver.Opera(options=options, executable_path=r'C:\path\to\operadriver.exe')
driver.get("http://google.com/")
This worked for me:
from selenium import webdriver
from selenium.webdriver.opera.options import Options
options = Options()
driver = webdriver.Opera(options=options)
driver.get("https://www.google.com")
I also get the same errors you showed but the URLs I need to open are being loaded automatically in Opera without issue.
You need to make sure your opera version matches the version of the driver.
check it by opening opera and enter this: opera://about
Ensure the operadriver.exe is on the same folder of the python script.
The driver can be downloaded here:
https://github.com/operasoftware/operachromiumdriver/releases

How to use Brave web browser with python, selenium and chromedriver?

I switched from Google's Chrome to Brave web browser and am having a hard time getting it to work with Brave like it did with Chrome. Brave is based on chromium so I guessed it should not be that hard. I made sure that my Brave and Chromedriver are on the same version like this,
~/some/path $ chromedriver --version
ChromeDriver 76.0.3809.126 (d80a294506b4c9d18015e755cee48f953ddc3f2f-refs/branch-heads/3809#{#1024})
My chromedriver is also in /user/bin,
~/path $ cd /usr/bin/
/usr/bin $ ls | grep chromedriver
chromedriver
And to check the Brave version, I get: Version 0.68.132 Chromium: 76.0.3809.132 (Official Build) (64-bit)
Then I run this code,
from selenium import webdriver
driver = webdriver.Chrome(executable_path='/usr/bin/brave-browser')
driver.get("http://www.python.org")
driver.close()
This opens a Brave window but then instead of getting the page the driver is pointed to, an exception is thrown,
Traceback (most recent call last):
File "webscrap.py", line 3, in <module>
driver = webdriver.Chrome(executable_path='/usr/bin/brave-browser')
File "/home/username/.local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/home/username/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 98, in start
self.assert_process_still_running()
File "/home/username/.local/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/brave-browser unexpectedly exited. Status code was: -11
I finally managed to make it work:
Try this python script (python3.7)
from selenium import webdriver
driver_path = "C:/Users/username/PycharmProjects/chromedriver.exe"
brave_path = "C:/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe"
option = webdriver.ChromeOptions()
option.binary_location = brave_path
# option.add_argument("--incognito") OPTIONAL
# option.add_argument("--headless") OPTIONAL
# Create new Instance of Chrome
browser = webdriver.Chrome(executable_path=driver_path, chrome_options=option)
browser.get("https://www.google.es")
cheers.
The executable_path key is used to pass the absolute path of the WebDriver binary i.e. the chromedriver executable.
To initiate a Brave browser session additionally you have to pass the absolute location of the brave-browser binary through the binary_location argument of an instance of ChromeOptions.
So the effective code block will be:
from selenium import webdriver
chromedriver_path = '/usr/bin/chromedriver'
brave_path = '/usr/bin/brave-browser'
option = webdriver.ChromeOptions()
option.binary_location = brave_path
browser = webdriver.Chrome(executable_path=driver_path, options=option)
browser.get("https://www.google.es")
References
You can find a couple of relevant detailed discussions in:
DeprecationWarning: use options instead of chrome_options error using ChromeDriver and Chrome through Selenium on Windows 10 system
How to initiate Brave browser using Selenium and Python on Windows
DeprecationWarning: use options instead of chrome_options error using Brave Browser With Python Selenium and Chromedriver on Windows
This also works in windows 10 with Brave browser. I downloaded Chromedriver and put it in the folder with Brave.exe.
from selenium import webdriver
driver_path = "C:\\Users\\5150s\\AppData\\Local\\Programs\\Python\\Python38\\chromedriver.exe"
brave_path = "C:\\Program Files (x86)\\BraveSoftware\\Brave-Browser\\Application\\brave.exe"
option = webdriver.ChromeOptions()
option.binary_location = brave_path
browser = webdriver.Chrome(executable_path=driver_path, options=option)
browser.get("https://www.google.es")
The solutions above gave me some errors. This code removes the executable path and options errors.
Chromedriver is in the pycharm folder.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
driver_path = "C:/Users/johnm/PycharmProjects/chromedriver.exe"
brave_path = "C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe"
s=Service(driver_path)
option = webdriver.ChromeOptions()
option.binary_location = brave_path
browser = webdriver.Chrome(service=s, options=option)
browser.get("https://www.google.es")

--headless flag no longer works after upgrade to chrome 76/chromedriver 76

I am running python selenium tests using headless chrome. After updating to chrome Version 76.0.3809.87 and chromedriver version ChromeDriver 76.0.3809.68, the chromeOptions that I use (see code sample below)... no longer work. i.e. the browser is launched (non headless) and the resolution settings are also not working
Anyone else seeing this after upgrading to chromedriver 75/76?
chrome_options = {'args': ['headless', '--window-size=1920,1080', 'no-sandbox', '--dns-prefetch-disable','--disable-dev-shm-usage']}
capabilities = {'browserName': 'chrome', 'chromeOptions':chrome_options}
cls.driver = webdriver.Chrome(desired_capabilities=capabilities)
You don't need to use desiredCapabilities to pass these arguments you can use Options instead. I have tested and it works.
Google Chrome - 76.0.3809.87
ChromeDriver - 76.0.3809.68
Selenium - 3.141.0
Python - 3.7.2
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)
driver.get('https://www.google.com')
driver.save_screenshot("screenshot.png")
driver.quit()
Check the screenshot obtained from the headless browser below.

Categories