Chrome not running without headless mode (Ubuntu 18.04) - python

So I'm working on a script that scrapes some data from a dynamic webpage and commits it to my database tables. For this, I've used Selenium in Python. It all worked perfectly fine until I restarted my system. Now chrome only works in headless mode and when I comment out that option so that I get to see an actual window of the chrome browser, I get this error
selenium.common.exceptions.WebDriverException: Message: unknown error:
Chrome failed to start: exited abnormally. (unknown error:
DevToolsActivePort file doesn't exist) (The process started from
chrome location /usr/bin/google-chrome is no longer running, so
ChromeDriver is assuming that Chrome has crashed.)
Solutions tried:
cross-checked the path of my chrome-binaries and it is valid
changed the order of adding options
uninstalled chrome and reinstalled it again
deleted the chromedriver and downloaded it again
restarted my system twice
googled the error and tried the solutions
EDIT: I have already tried adding the --no-sandbox option before commenting it out here as shown in the snapshot
One thing I would want to mention is that my root space is quite less and only 340 mb of free space is left. Does that affect?

To see an actual window of the chrome browser removing the argument -headless is perfect.
However, I would suggest to remove all the unwanted options and execute your test with the minimal lines of code as follows:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('start-maximized')
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=chrome_options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get("http://google.com/")
In case you see the error as:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally. (unknown error: DevToolsActivePort file doesn't exist) (The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
You may need to add the argument --no-sandbox.
So the solution is to add back the argument:
chrome_options.addArguments("--no-sandbox");
chrome_options.addArguments("--disable-dev-shm-usage");
You can find a detailed discussion in WebDriverException: unknown error: DevToolsActivePort file doesn't exist while trying to initiate Chrome Browser
Additional considerations
Ensure that:
Selenium is upgraded to current levels Version 3.141.59.
ChromeDriver is updated to current ChromeDriver v83.0 level.
Chrome is updated to current Chrome Version 83.0 level. (as per ChromeDriver v83.0 release notes)
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
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.
Reference
You can find a detailed discussion in:
Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed

Related

Selenium driven ChromeDriver can't find Chrome binary

I just uninstalled Chrome because it was acting strange (fixed now) and after this Selenium in Python is not able to identify the Chrome driver binary, which is extremely strange because it should be completely unaffected and it is in a different location and a different version from the chrome I use on my desktop, code is as follows and has worked for years now.
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--load-extension='+exension_path)
driver = webdriver.Chrome(executable_path=chrome_driver_folder,options=chrome_options)
Anyone has any idea what on earth is going on? I get the follow error:
WebDriverException: Message: unknown error: cannot find Chrome binary
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64)
This error message...
WebDriverException: Message: unknown error: cannot find Chrome binary (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.18362 x86_64)
...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:
You are using chromedriver=2.40
Release Notes of chromedriver=2.40 clearly mentions the following :
Supports Chrome v66-68
As you have uninstalled Chrome and reinstalled presumably you are using the latest chrome=85.0
Release Notes of ChromeDriver v85.0 clearly mentions the following :
Supports Chrome version 85
So there is a clear mismatch between ChromeDriver v2.40 and the Chrome Browser v85.0
Solution
Ensure that:
Selenium is upgraded to current released Version 3.141.59.
ChromeDriver is updated to current ChromeDriver v85.0 level.
Chrome is updated to current Chrome Version 85.0 level. (as per ChromeDriver v85.0 release notes)
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
In order to have a clean code and to stop track the chrome path/version, I recommend to you to use webdriver_manager
Install it
pip install webdriver_manager
and use it like this
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
chrome_options.add_argument('--load-extension='+exension_path)
driver = webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=options)
but if don't want to use it here is the code for local browser
chrome_options = Options()
chrome_options.add_argument('--load-extension='+exension_path)
chrome_options.binary_location = 'YOUR_PATH'
driver = webdriver.Chrome(executable_path=os.path.abspath(“chromedriver"), chrome_options=chrome_options)
but I totally recommend using the first version.

Message: session not created: This version of ChromeDriver only supports Chrome version 85

my code is as follows:
from selenium import webdriver
driver = webdriver.Chrome(executable_path="/webdriver/chromedriver.exe")
driver.get('http://google.com/')
When I run the program, the browser opens for half a second then closes down and gives the error
Message: session not created: This version of ChromeDriver only supports Chrome version 85
I'm using this version of chromedriver for my program: https://chromedriver.storage.googleapis.com/index.html?path=85.0.4183.38/
Any help is appreciated.
This error message...
Message: session not created: This version of ChromeDriver only supports Chrome version 85
...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:
You are using the latest chrome=84.0
Release Notes of ChromeDriver v84.0 clearly mentions the following :
Supports Chrome version 84
Possibly you have downloaded chromedriver=85.0
Release Notes of chromedriver=85.0 clearly mentions the following :
Supports Chrome version 85
So there is a clear mismatch between Chrome Browser v84.0 and ChromeDriver 85.0
Solution
Ensure that:
Selenium is upgraded to current levels Version 3.141.59.
ChromeDriver is updated to current ChromeDriver v84.0 level.
Chrome is updated to current Chrome Version 84.0 level. (as per ChromeDriver v84.0 release notes)
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
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.
Chrome browser are updating time to time so you need to use exact driver exe according to your browser version please check your browser version and download driver exe based to match to your browser version in https://chromedriver.chromium.org/downloads and set path and refresh project and rerun
driver.get('http://google.com/')
insted of this single quotation use below double quotation
driver.get("http://google.com/")

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81 using Selenium ChromeDriver v81

I imported webdriver from selenium and os. I want to be able to run this piece of code successfully:
driver = webdriver.Chrome(executable_path= os.path.abspath('') + '/chromedriver')
The error I'm getting:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81
I'm using python 2.7 on a MAC OSX.
I have version 81.0.4044.138 of the chromedriver installed from https://sites.google.com/a/chromium.org/chromedriver/downloads
in the same workspace directory, and it is named 'chromedriver', but it's like my webdriver doesn't recognize it. I would appreciate any suggestions!
This error message...
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 81
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
Analysis
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You are using ChromeDriver 81.0
Release Notes of ChromeDriver 81.0 clearly mentions the following :
Supports Chrome version 81
Most probhably the Chrome Browser got updated to Chrome v83.0 as a part of the recent push.
Release Notes of ChromeDriver v83.0 clearly mentions the following :
Supports Chrome version 83
Your Selenium Client version is unknown to us.
So there is a clear mismatch between ChromeDriver v81.0 and the Chrome Browser v83.0
Solution
Ensure that:
Selenium is upgraded to current levels Version 3.141.59.
ChromeDriver is updated to current ChromeDriver v83.0 level.
Chrome is updated to current Chrome Version 83.0 level. (as per ChromeDriver v83.0 release notes)
If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.
Execute your #Test as non-root user.
This is happening in most cases due to differences between the Chrome web driver version and the Chrome Browser version.
I would suggest you to do the following:
1- Take a backup of your work.
2- Update Chrome Browser to the latest version.
3- Install the latest version of the chrome browser.
4- Kill any chromedriver process that is running in the background.
5- Clean up your code and give it a try.

selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service error using ChromeDriver Chrome through Selenium Python

So I have made a program on one computer using selenium and that worked, Now using it in another computer I get this error:
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver
Now this same issue was mention in:
Selenium python: Can not connect to the Service %s" % self.path
Selenium python: Can not connect to the Service %s" % self.path
Selenium and Python3 ChromeDriver raises Message: Can not connect to the Service chromedriver
however the solutions mentioned didnt work.
I am using chrome version 79 and have installed chromedriver 79, I tested writing chromedriver in command line and that works which means path is configured right, I have made sure 127.0.0.1 localhost is also in etc/hosts
Below is my code which works on my computer (so i doubt its an issue with the code):
chrome_options = Options()
chrome_options.add_argument("--headless")
with webdriver.Chrome(chrome_options=chrome_options) as driver:
driver.set_window_size(800, 460) # takes two arguments, width and height of the browser and it has to be called before using get()
driver.execute_script("document.body.style.zoom='150%'")
driver.get("file:\\"+url) # takes one argument, which is the url of the website you want to open
driver.find_element_by_tag_name('body').screenshot(output) # avoids scrollbar
In the last question I also tried this modification:
chrome_options = Options()
chrome_options.add_argument("--headless")
with webdriver.Chrome("C:\\chromedriver.exe",chrome_options=chrome_options) as driver:
driver.set_window_size(800, 460) # takes two arguments, width and height of the browser and it has to be called before using get()
driver.execute_script("document.body.style.zoom='150%'")
driver.get("file:\\"+url) # takes one argument, which is the url of the website you want to open
driver.find_element_by_tag_name('body').screenshot(output) # avoids scrollbar
which would instead give me this almost identical error message:
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service C:\chromedriver.exe
I am unsure where the issue could lie.
I am using windows by the way.
EDIT: Things I tried and didn't work:
1- running everything as both admin and normal
2- re-installing chrome
3- using the beta-chroma 80 and webdriver 80
4- using normal chrome 79 and webdriver 79
5- Having both the script and the driver in the same directory (while using a
correct path)
6- Having an external path and have it setup as needed
7- Using it in the PATH folder.
8- Adding "127.0.0.1 localhost" to etc/hosts
9- Running service test
I have ensured in every test that everything was in it's correct placement, I have ran a reboot before every new test, and they always give me the same error, which also happens to occur if I had an incorrect path as well, but once I ran the code for a service and it gave me a different error as I had my webdriver in C:/ which required admin privilages, however re-running the test again with the correct privilages gave back the same error
Update the issue isn't exclusive to the chrome driver. Even following setup instructions for either the Firefox or edge drivers end up on the same issues. It makes me suspect that the connection is facing some issue. I have tried running the test codes provided by Mozilla for the setup and it didn't work.
Unsure if that does help much or at all.
This error message...
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver
...implies that the ChromeDriver was unable to initiate/spawn a new Browsing Context i.e. Chrome Browser session.
You need to take care of a couple of things:
Ensure that you have downloaded the exact format of the ChromeDriver binary from the download location pertaining to your underlying OS among:
chromedriver_linux64.zip: For Linux OS
chromedriver_mac64.zip: For Mac OSX
chromedriver_win32.zip: For Windows OS
Ensure that /etc/hosts file contains the following entry:
127.0.0.1 localhost
Ensure that ChromeDriver binary have executable permission for the non-root user.
Ensure that you have passed the proper absolute path of ChromeDriver binary through the argument executable_path as follows:
with webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=chrome_options) as driver:
So your effective code block will be:
options = Options()
options.add_argument("--headless")
options.add_argument('--no-sandbox') # Bypass OS security model
options.add_argument('--disable-gpu') # applicable to windows os only
options.add_argument("--disable-dev-shm-usage") # overcome limited resource problems
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
with webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', options=options) as driver:
driver.set_window_size(800, 460) # takes two arguments, width and height of the browser and it has to be called before
driver.execute_script("document.body.style.zoom='150%'")
driver.get("file:\\"+url) # takes one argument, which is the url of the website you want to open
driver.find_element_by_tag_name('body').screenshot(output) # avoids scrollbar
Mandatory Considerations
Finally, to avoid incompatibility between the version of the binaries you are using 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.
References
You can find a couple of reference discussions in:
Python Selenium “Can not connect to the Service %s” % self.path in linux server
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver.exe while opening chrome browser
How to configure ChromeDriver to initiate Chrome browser in Headless mode through Selenium?

SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 76 with Selenium ChromeDriver

I am currently using Chrome 75 and I've downloaded the compatible Chromedriver for linux. I've also added it to the PATH variable. However, when I attempt initializing a driver with driver = webdriver.Chrome() I get the following error:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 76
What I get from this message is that my Chromedriver is ment for Chrome version 76, but both my Chromedriver and Chrome browser are version 75.
I even tried deleting the Chromedriver completely from my files and I still get the same error message
This error message...
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 76
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your code trials and the error stack trace would have helped us to debug the issue in a better way. Though you mentioned about compatible Chromedriver for linux but your program while in execution picks up the ChromeDriver v76.0.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
Release Notes of chromedriver=76.0 clearly mentions the following :
Supports Chrome version 76
Solution
Ensure you have:
Deleted all the existing different versions of Chromedriver from your system.
ChromeDriver is updated to current ChromeDriver v76.0 level.
Additionally, ensure you pick up the latest release of ChromeDriver v76.0 i.e. ChromeDriver v76.0.3809.126.
Chrome is updated to current Chrome Version 76.0 level. (as per ChromeDriver v76.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 through Revo Uninstaller 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
This error implement:
You need to download your version of chrome driver:
You can download your version of chrome driver via clicking here:
https://chromedriver.storage.googleapis.com/index.html?path=75.0.3770.140/

Categories

Resources