I'm currently running a selenium python script on my EC2 machine.
Google-chrome version (100.0.4896.60)
Chrome driver (100.0.4896.60)
Red hat (8.7)
Python (3.6.8)
Selenium (3.141.0)
Pytest (7.0.1)
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
#argument to switch off suid sandBox and no sandBox in Chrome
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument("--remote-debugging-port=9222")
# chrome_options.add_argument('--start-maximized')
chrome_options.add_argument('--headless')
#chrome_options.add_argument("--window-size=1920,1080")
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-popup-blocking')
chrome_options.add_argument("--incognito")
userAgent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36"
chrome_options.add_argument(f'user-agent={userAgent}')
chrome_options.add_argument('ignore-certificate-errors')
driver = webdriver.Chrome("/usr/local/share/chromedriver", options=chrome_options)
driver.get('http://www.google.com')
print(driver.title)
driver.quit()
When I run the script, I get the following error.
================================================================================================================== ERRORS ===================================================================================================================
_________________________________________________________________________________________________________ ERROR collecting main.py __________________________________________________________________________________________________________
main.py:21: in <module>
driver = webdriver.Chrome("/usr/local/share/chromedriver", options=chrome_options)
/usr/local/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py:81: in __init__
desired_capabilities=desired_capabilities)
/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py:157: in __init__
self.start_session(capabilities, browser_profile)
/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py:252: in start_session
response = self.execute(Command.NEW_SESSION, parameters)
/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py:321: in execute
self.error_handler.check_response(response)
/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py:242: in check_response
raise exception_class(message, screen, stacktrace)
E selenium.common.exceptions.WebDriverException: Message: chrome not reachable
========================================================================================================== short test summary info ==========================================================================================================
ERROR main.py - selenium.common.exceptions.WebDriverException: Message: chrome not reachable
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
There was an update to google-chrome on my red hat server that caused it to upgrade to version 109, I was told to downgrade version back to 100, so avoid any breaks to our scripts in the short term. Now the versions of google-chrome and chromedriver are matching but I'm still seeing error that chrome cannot be reached. I already ensured that chrome driver is at correct path as well as correct permissions. I set permissions on google chrome using "chmod +x chromedriver". Not sure what else to do.
The expected outcome of this script is very simple, as this is not my main code but an example. When running any script on this machine, I get the same error.
You don't need all those arguments. To enable headless mode barely you need the following arguments:
chrome_options.add_argument('--headless')
chrome_options.add_argument("--window-size=1920,1080")
chrome_options.add_argument(f'user-agent={userAgent}')
Remove the other arguments:
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument("--remote-debugging-port=9222")
chrome_options.add_argument('--start-maximized')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-popup-blocking')
chrome_options.add_argument("--incognito")
chrome_options.add_argument('ignore-certificate-errors')
And execute your program as:
For Selenium v3.x:
driver = webdriver.Chrome(executable_path=r'/usr/local/share/chromedriver', options=chrome_options)
driver.get('http://www.google.com')
For selenium4:
driver = webdriver.Chrome(service=Service('/usr/local/share/chromedriver'), options=chrome_options)
driver.get('http://www.google.com')
Related
I'm trying to rum selenium on ChromeDriver 106.0.5249 but face with Error "DevToolsActivePort file doesn't exist"
I've checked that Chromedriver and Chrome browser versions are equal.
I set all configs as was recommended in other public, but it did not help.
I'm running it on Ubuntu 22-04. Locally on my Mac everything works as expected
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--window-size=1920,1080")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument('--ignore-certificate-errors')
chrome_options.add_argument("--incognito")
chrome_options.add_argument("--disable-default-apps")
What can I try also?
I want so scrape some dynamic url (the page is built using JavaScript and does a redirect to an external page). I understand that I need to use a headless browser and I am using Selenium with Chrome driver. The following code does what I want on my Windows machine:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
class MySpider(scrapy.Spider):
name = 'my_spider'
def __init__(self):
self.driver = webdriver.Chrome(ChromeDriverManager().install())
def parse(self, response):
link = "some-url-which-uses-javascript.com"
self.driver.get(link)
time.sleep(1) # without this wait, driver.current_url is not the final redirect
url = self.driver.current_url
But when I run the same code on my Ubuntu server (which does not have GUI) I get the following error:
builtins.ValueError: Could not get version for Chrome with this
command: google-chrome --version || google-chrome-stable --version
I have installed both google-chrome-stable and chromium-chromedriver on the Ubuntu server.
I have also tried the following code:
class MySpider(scrapy.Spider):
name = 'my_spider'
def __init__(self):
# self.driver = webdriver.Chrome(ChromeDriverManager().install())
# self.driver = webdriver.Chrome('/usr/bin/chromedriver')
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
self.driver = webdriver.Chrome('/usr/bin/chromedriver', chrome_options=chrome_options)
Bu I get the following 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.)
Just to show that I have done my due diligince, I have already either tried the suggested answers or at least read them over and tried to understand, for the following questions:
Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed
The process started from chrome location C:\..\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed
Selenium python library via docker, Chrome error failed to start: exited abnormally
Chrome crashes when using Selenium (No answer posted but I still looked it over)
How to fix "usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed" error in Linux?
- For this one I substituted the '/usr/bin/google-chrome' with '/etc/alternatives/google-chrome', still didn't work.
The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed for Selenium
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed with ChromeDriver and Selenium in Python
python linux selenium: chrome not reachable
unknown error: Chrome failed to start: crashed(selenium ,headless mode)
python selenium: WebDriverException: Message: chrome not reachable
Selenium chrome failed to start
WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium through Python on VPS
Getting "Chrome not reachable" error while executing test scripts in Selenium Grid With Chrome browser
Selenium webdriver error Chrome failed to start
org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: crashed (headless chrome)
Python : Selenium - Message: unknown error: Chrome failed to start: exited abnormally
I am getting a common error that I have seen here on Stack Overflow, when running Selenium with Python on my Amazon Linux server I get the following results:
Traceback (most recent call last):
File "test-selenium-chrome.py", line 15, in <module>
driver = webdriver.Chrome(options=options, executable_path='/usr/local/bin/chromedriver') # Optional argument, if not specified will search path.i
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(chrome not reachable)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Here is my code:
#!/usr/bin/python3
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from pyvirtualdisplay import Display
options = Options()
options.binary_location = '/usr/bin/google-chrome'
options.add_argument('--disable-extensions')
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--remote-debugging-port=9515')
options.add_argument('--disable-setuid-sandbox')
display = Display(visible=0, size=(800, 800))
display.start()
driver = webdriver.Chrome(options=options, executable_path='/usr/local/bin/chromedriver') # Optional argument, if not specified will seearch path.i
driver.maximize_window()
driver.get('http://www.google.com/')
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()
I am using Google Chrome version 79.0.3945.130, and the corresponding chromedriver version ChromeDriver 79.0.3945.36 as speicified in https://sites.google.com/a/chromium.org/chromedriver/downloads
Additional info, if I just run google-chrome from the command line, I get:
[ec2-user#ip-xxx-xx-xx-xxx bin]$ pwd
/usr/bin
[ec2-user#ip-xxx-xx-x-xxx bin]$ google-chrome
Segmentation fault
Any help is greatly appreciated.
This error message...
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(chrome not reachable)
(The process started from chrome location /usr/bin/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 Browsing Context i.e. Chrome Browser session.
As per the discussion in Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed, the expected default location of google-chrome on linux is:
/usr/bin/google-chrome
Note: For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary.
So ideally, the following minimal code block should have worked:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = '/usr/bin/google-chrome'
driver = webdriver.Chrome(options=options, executable_path='/usr/local/bin/chromedriver')
driver.get('http://www.google.com/')
But it seems, when you try to initiate a Chrome session manually, Segmentation fault occurs i.e. crashes as follows:
[ec2-user#ip-xxx-xx-xx-xxx bin]$ pwd
/usr/bin
[ec2-user#ip-xxx-xx-x-xxx bin]$ google-chrome
Segmentation fault
Segmentation fault
Segmentation fault (shortened as segfault) or access violation is a fault or failure condition raised by hardware with memory protection, notifying an operating system that the software has attempted to access a restricted area of memory. The OS kernel will, in response, usually perform some corrective action, generally passing the fault on to the offending process (your script) by sending the process a signal.
In short, it’s a helper mechanism to restrict programs/scripts from corrupting the memory which does not belong to it. See more here.
Reason and Solutions
The pottential reasons and solutions are:
Chrome is not at all installed within the system, so you have to install Chrome
Chrome is not installed at the default location, so you have to pass the correct location of chrome executable through binary_location property.
The symlink /usr/bin/google-chrome to the actual Chrome binary got corrupted, so you may have to create the symlink.
The user doesn't have required access rights /usr/bin/google-chrome, so you have provide the access rights.
I had the same problem, just remove --headless line and it's work well.
I have already read a couple of threads about this problem but none of them really helped me so here goes. I am trying to use selenium webdriver on google colab. i had some problems installing it but finally with the code below, i was able to install it:
!pip install selenium
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
import sys
sys.path.insert(0,'/usr/lib/chromium-browser/chromedriver')
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
wd = webdriver.Chrome('chromedriver',chrome_options=chrome_options)
wd.get("https://www.webite-url.com")
however, now when i run this two lines of codes:
from selenium import webdriver
driver = webdriver.Chrome()
this is the error I get:
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/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
It runs on server which doesn't have video card and monitor so you have to always use --headless and maybe other options too
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('chromedriver', chrome_options=chrome_options)
driver.get("...your_url...")
Chrome version: 68.0.3440.106
Chrome webdriver version: ChromeDriver 2.41.578737
Python Version : Python 3.5.2
I write this code in python:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
o = webdriver.ChromeOptions()
o.add_argument("disable-extensions");
o.add_argument("--start-maximized");
driver = webdriver.Chrome(executable_path=r"chromedriver.exe",options=o)
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
after few seconds chrome opened with this error:
and nothing happend till i close chrome and get this exception:
Traceback (most recent call last):
File ".../game.py", line 8, in <module>
driver = webdriver.Chrome(executable_path=r"chromedriver.exe",options=o)
File "...\Python\Python35-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "...\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "...\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 251, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "...\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "...\Python\Python35-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally
(unknown error: unable to discover open pages)
(The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 x86_64)
use correct argument for disabling extension:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
o = Options()
#o.add_argument("--disable-extensions"); #here
o.add_experimental_option("useAutomationExtension", false); #you can try this as well
o.add_argument("--start-maximized");
driver = webdriver.Chrome(executable_path=r"chromedriver.exe",chrome_options=o)
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
Today I was the same trouble and I fixed using:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
o = webdriver.ChromeOptions()
o.add_argument("disable-extensions")
o.add_argument("--start-maximized")
o.binary_location = "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" ## This line define path of browser. In this case, Google Chrome
driver = webdriver.Chrome(executable_path=r"chromedriver.exe",options=o)
driver.get("http://www.python.org")
assert "Python" in driver.title
elem = driver.find_element_by_name("q")
elem.clear()
elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()
I recently had this issue using TeamCity, which was caused by chrome (and chromedriver) not shutting down after executing my script.
inserting "taskkill /f /im chrome.exe" and "taskkill /f /im chromedriver.exe" fixed this issue.
This error message...
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally
(unknown error: unable to discover open pages)
(The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe 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 seems that the chrome binary i.e. chrome.exe and the associated files are no more available/accessible from the default location of:
C:\Program Files (x86)\Google\Chrome\Application\
The possible reasons are:
Chrome previously installed at the default location got corrupted/deleted.
If you have installed Chrome Browser at a non-standard location you need to do:
opt = webdriver.ChromeOptions()
opt.binary_location("/path/to/other/chrome/binary");
Here you find a detailed discussion on Cannot find Chrome binary with Selenium in Python for older versions of Google Chrome
Additional considerations
Chrome and ChromeDriver are present in the desired location.
Chrome and ChromeDriver are having executable permission for non-root (non-administrator) users.
Upgrade Selenium to current levels Version 3.14.0.
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
(WindowsOS only) Use CCleaner tool to wipe off all the OS chores before and after the execution of your Test Suite.
(LinuxOS only) Free Up and Release the Unused/Cached Memory in Ubuntu/Linux Mint before and after the execution of your Test Suite.
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 a non-root user.
Run the selenium server with webdriver-manager start from the machine with the desktop (don't use a remote session to start the selenium server).
We faced this issue using Java, Cucumber, Maven, Serenity, and IntelliJ. After trying everything the solution was so easy:
Just run IntelliJ as administrator.