Chromedriver failed to start - python

I'm working with the most recent version of Chromedriver, but it seems to be failing to start. When I try to start tests with it, it simply loads to a blank screen with "data;," in the address bar, and prints this in the debug console:
====== WebDriver manager ======
Get LATEST chromedriver version for google-chrome 109.0.5414
Driver [C:\Users\Peter.[redacted]\.wdm\drivers\chromedriver\win32\109.0.5414\chromedriver.exe] found in cache
[ FAIL ] WebDriverException: Message: unknown error: Chrome failed to start: exited normally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
[ FAIL ] AttributeError: 'NoneType' object has no attribute 'close'
I have tried to delete the versions of chromedriver, manually download and replace the executable, uninstal and reinstall webdrever-manager, and have tried different versions of webdriver-manager. Nothing has worked except for swtiching to other webdrivers like firefox or remote-chrome, but both of those have conflicts with other libraries we use so they aren't options. Any help would be must appreciated.

This error usually occurs when there is an incompatibility between versions of Google Chrome, Chromedriver and/or Selenium. Here are some suggestions that may help resolve the issue:
Make sure you are using the latest version of Google Chrome and that it is compatible with the Chromedriver version you are using.
Make sure the Chromedriver version you are using is compatible with the Selenium version you are using. Make sure they are updated to the latest versions.
Try setting the 'disable-dev-shm-usage' property to true in Chrome's configuration. This can help avoid issues with shared memory usage. Example:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=chrome_options)
Try specifying the path to the Chrome executable explicitly instead of using the default path. For example:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = '/path/to/chrome'
driver = webdriver.Chrome(options=chrome_options)

Related

selenium.common.exceptions.SessionNotCreatedException: Message: Failed to start browser /snap/firefox/current/firefox.launcher

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.

Python: ChromeDriverManager chrome downloads from incorrect url of latest chromedriver

My log shows that the Chromedriver downloads from a 3 part version number rather than a 4-part
10:32:22 INFO About to download new driver from https://chromedriver.storage.googleapis.com/104.0.5112/chromedriver_win32.zip
It should be
https://chromedriver.storage.googleapis.com/104.0.5112.79/chromedriver_win32.zip
(i.e have the 4th part of version)
Ive tried setting the latest_release_url to a 4 part version number but it doesnt overwrite it. Code below
full_version = '104.0.5112.79'
caps = {"pageLoadStrategy": "normal"}
latest_release_url = 'https://chromedriver.storage.googleapis.com/{LATEST_RELEASE}_{full_version}'
driver = webdriver.Chrome(
ChromeDriverManager(
latest_release_url=latest_release_url).install(),
options=options,
desired_capabilities=caps)
Not sure in which os variant/flavor or specific circumstances or Python version you are seeing the shortened download url as:
https://chromedriver.storage.googleapis.com/104.0.5112/chromedriver_win32.zip
However, on my windows-10 64-bit operating system, x64-based processor system using using webdrivermanager-python v3.5.2, python v3.9.0, selenium4 v4.4.0 and the following line of code:
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
I can properly see the full path i.e.
https://chromedriver.storage.googleapis.com/104.0.5112.79/chromedriver_win32.zip
within the logs:
====== WebDriver manager ======
Current google-chrome version is 104.0.5112
Get LATEST chromedriver version for 104.0.5112 google-chrome
There is no [win32] chromedriver for browser in cache
Trying to download new driver from https://chromedriver.storage.googleapis.com/104.0.5112.79/chromedriver_win32.zip
Driver has been saved in cache [C:\Users\username\.wdm\drivers\chromedriver\win32\104.0.5112.79]
Update
Though as per selenium/py/CHANGES page Selenium 4.4.2 is the latest release but may be not be stable.
To be on the safer side ideally we need to use the version mentioned in the Downloads webpage, which is v4.4.0

How to use selenium chrome options?

So I have had this code for sometime that worked without an issue for what I can recall. However, it has recently been raising an issue when I run it. Here is the code
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(options=chrome_options)
here is the error
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.
First, you need to install ChromeDriver if it's not installed. (https://chromedriver.chromium.org/downloads)
Then, you need to add it to the PATH environment variable and you're good to go!

Selenium crashing when running headless chromedriver on my raspberry pi

I downloaded chromedriver on to my raspberry pi (no gui os) from here: https://launchpad.net/ubuntu/trusty/armhf/chromium-chromedriver/65.0.3325.181-0ubuntu0.14.04.1
And I then installed it using dpkg -i and I can verify it installed to '/usr/lib/chromium-browser/chromedriver'.
When I try to run my script that uses selenium:
options = Options()
options.add_argument(f'user-agent={USER_AGENT}')
options.add_argument('--window-size=1024,768')
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('disable-infobars')
options.add_argument("--disable-extensions")
driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', options=options)
# Fetch video url.
driver.get(url)
It crashes with the following error:
selenium.common.exceptions.WebDriverException: Message: unknown error:
session deleted because of page crash
from tab crashed
This error occurs on:
driver.get(url)
How would I fix this? Is it how I set up selenium in my code? Or how I installed it?
Edit: Is it possible that the error is caused by the version of chromium-chromedriver installed from launchpad is version 65 and my chromium-broswer install is version 72?
If so how would I install an older version of chromium-browser?
I suspect this has nothing to do with running in headless mode. How did you "verify it installed to '/usr/lib/chromium-browser/chromedriver'"?
You are saying the code:
driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver')
driver.get(url)
runs without problems? I would have thought it would need a full path of:
driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver/chromedriver.exe')
driver.get(url)
Since the chromedriver.exe is a file and not a folder (although I personally just have chromedriver.exe in the same directory so I omit this argument...perhaps I do not understand it fully). If that works, you should systematically add options 1 by 1 until it breaks so you know exactly what option is breaking it.

Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed

Recently I switched computers and since then I can't launch chrome with selenium. I've also tried Firefox but the browser instance just doesn't launch.
from selenium import webdriver
d = webdriver.Chrome('/home/PycharmProjects/chromedriver')
d.get('https://www.google.nl/')
i get the following error:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.43.600233, platform=Linux 4.15.0-38-generic x86_64)
i have the latest chrome version and chromedriver installed
EDIT:
After trying #b0sss solution i am getting the following error.
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(chrome not reachable)
(The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so chromedriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.15.0-38-generic x86_64)
Try to download HERE and use this latest chrome driver version:
https://sites.google.com/chromium.org/driver/
Try this:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome('/home/<user>/chromedriver',chrome_options=chrome_options)
d.get('https://www.google.nl/')
This error message...
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /opt/google/chrome/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
...implies that the ChromeDriver was unable to initiate/spawn a new WebBrowser i.e. Chrome Browser session.
Your main issue is the Chrome browser is not installed at the default location within your system.
The server i.e. ChromeDriver expects you to have Chrome installed in the default location for each system as per the image below:
1For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.
Solution
In case you are using a Chrome executable in a non-standard location you have to override the Chrome binary location as follows:
Python Solution:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = "C:\\path\\to\\chrome.exe" #chrome binary location specified here
options.add_argument("--start-maximized") #open Browser in maximized mode
options.add_argument("--no-sandbox") #bypass OS security model
options.add_argument("--disable-dev-shm-usage") #overcome limited resource problems
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'C:\path\to\chromedriver.exe')
driver.get('http://google.com/')
Java Solution:
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions opt = new ChromeOptions();
opt.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"); //chrome binary location specified here
options.addArguments("start-maximized");
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
options.setExperimentalOption("useAutomationExtension", false);
WebDriver driver = new ChromeDriver(opt);
driver.get("https://www.google.com/");
hope this helps someone. this worked for me on Ubuntu 18.10
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument('--no-sandbox')
driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', options=chrome_options)
driver.get('http://www.google.com')
print('test')
driver.close()
I encountered the exact problem running on docker container (in build environment). After ssh into the container, I tried running the test manually and still encountered
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome-stable is
no longer running, so ChromeDriver is assuming that Chrome has crashed.)
When I tried running chrome locally /usr/bin/google-chrome-stable, error message
Running as root without --no-sandbox is not supported
I checked my ChromeOptions and it was missing --no-sandbox, which is why it couldn't spawn chrome.
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
chromeOptions: { args: %w(headless --no-sandbox disable-gpu window-size=1920,1080) }
)
I had a similar issue, and discovered that option arguments must be in a certain order. I am only aware of the two arguments that were required to get this working on my Ubuntu 18 machine. This sample code worked on my end:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
d = webdriver.Chrome(executable_path=r'/home/PycharmProjects/chromedriver', chrome_options=options)
d.get('https://www.google.nl/')
For RobotFramework
I solved it! using --no-sandbox
${chrome_options}= Evaluate sys.modules['selenium.webdriver'].ChromeOptions() sys, selenium.webdriver
Call Method ${chrome_options} add_argument test-type
Call Method ${chrome_options} add_argument --disable-extensions
Call Method ${chrome_options} add_argument --headless
Call Method ${chrome_options} add_argument --disable-gpu
Call Method ${chrome_options} add_argument --no-sandbox
Create Webdriver Chrome chrome_options=${chrome_options}
Instead of
Open Browser about:blank headlesschrome
Open Browser about:blank chrome
Assuming that you already downloaded chromeDriver, this error is also occurs when already multiple chrome tabs are open.
If you close all tabs and run again, the error should clear up.
in my case, the error was with www-data user but not with normal user on development. The error was a problem to initialize an x display for this user. So, the problem was resolved running my selenium test without opening a browser window, headless:
opts.set_headless(True)
A simple solution that no one else has said but worked for me was not running without sudo or not as root.
The solutions that every body provide here is good for Clear the face of the issue but
All you need to solve this problem is that You have to run The App on non-root user
on linux.
According to this post
https://github.com/paralelo14/google_explorer/issues/2#issuecomment-246476321
I had the same problem but it was solved just by reinstalling chrome again with the commands below:
$ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
$ sudo apt install ./google-chrome-stable_current_amd64.deb
This error has been happening randomly during my test runs over the last six months (still happens with Chrome 76 and Chromedriver 76) and only on Linux. On average one of every few hundred tests would fail, then the next test would run fine.
Unable to resolve the issue, in Python I wrapped the driver = webdriver.Chrome() in a try..except block in setUp() in my test case class that all my tests are derived from. If it hits the Webdriver exception it waits ten seconds and tries again.
It solved the issue I was having; not elegantly but it works.
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
try:
self.driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)
except WebDriverException as e:
print("\nChrome crashed on launch:")
print(e)
print("Trying again in 10 seconds..")
sleep(10)
self.driver = webdriver.Chrome(chrome_options=chrome_options, desired_capabilities=capabilities)
print("Success!\n")
except Exception as e:
raise Exception(e)
I came across this error on linux environment. If not using headless then you will need
from sys import platform
if platform != 'win32':
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
Faced with this issue trying to run/debug Python Selenium script inside WSL2 using Pycharm debugger.
First solution was to use --headless mode, but I prefer to have Chrome GUI during the debug process.
In the system terminal outside Pycharm debugger Chrome GUI worked nice with DISPLAY env variable set this way (followed guide here):
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
Unfortunately ~/.bashrc is not running in Pycharm during the debug, export is not working.
The way I've got Chrome GUI worked from Pycharm debugger: run echo $DISPLAY in WSL2, paste ip (you've got something similar to this) 172.18.144.1:0 into Pycharm Debug Configuration > Environment Variables:
Just do not run the script as the root user (in my case).
i had same problem. I was run it on terminal with "sudo geany", you should run it without "sudo" just type on terminal "geany" and it is solved for me.
i faced the same problem but i solved it by moving the chromedriver to this path
'/opt/google/chrome/'
and this code works correctly
from selenium.webdriver import Chrome
driver = Chrome('/opt/google/chrome/chromedrive')
driver.get('https://google.com')
In my case, chrome was broken. following two lines fixed the issue,
apt -y update; apt -y upgrade; apt -y dist-upgrade
apt --fix-broken install
Fixed it buy killing all the chrome processeses running in the remote server before running my script.
That may explain why some answers that recommend you run your script as root works.
$ pkill -9 chrome
$ ./my_script.py
Maybe when you where developing in local, you used options.headless=False in order to see what is the browser doing but you forgot to change it to True in the vm.
For me, the root issue was that the google-chrome/chromedriver version were not compatible with the Selenium version.
Seleniumn and Chrome were working fine until a few days ago and I started getting this missing DevToolsActivePort issue. After trying all sorts of solutions on this thread, it finally occurred to me that the Chrome version might not be compatible with the Selenium version.
Versions at the time of the initial error:
# Below combo does NOT work
Python 3.7.3
selenium==3.141.0
Google Chrome 110.0.5481.77
ChromeDriver 110.0.5481.77
I then downgraded Chrome and ChromeDriver to 109.0.5414.74 but still faced the same error. I checked the versions on a different machine and saw that this combo worked:
# Below combo works
Python 3.7.6
selenium==3.141.0
Google Chrome 80.0.3987.100
ChromeDriver 80.0.3987.16
However, I wasn't able to find a download for Google Chrome V80. This comment had a download to V97 so that's the version I went with. There might be higher versions of Google Chrome that do work but after spending so many days fixing this, I was eager to move onto something else.
sudo apt-get purge google-chrome-stable
sudo wget http://dl.google.com/linux/chrome/deb/pool/main/g/google-chrome-stable/google-chrome-stable_97.0.4692.71-1_amd64.deb && \
sudo dpkg -i google-chrome-stable_97.0.4692.71-1_amd64.deb && \
sudo apt-mark hold google-chrome-stable
wget https://chromedriver.storage.googleapis.com/97.0.4692.71/chromedriver_linux64.zip
sudo unzip chromedriver_linux64.zip chromedriver -d /usr/local/bin
After that, my Selenium calls were able to work again. The final version combo:
# Below combo works
Python 3.7.3
selenium==3.141.0
ChromeDriver 97.0.4692.71
Google Chrome 97.0.4692.71
Make sure that both the chromedriver and google-chrome executable have execute permissions
sudo chmod -x "/usr/bin/chromedriver"
sudo chmod -x "/usr/bin/google-chrome"

Categories

Resources