Reputation: 346
I am trying to open the URL using selenium in chrome. I have chromedriver available with me.
following is the code I want to execute.
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--disable-infobars")
driver = webdriver.Chrome(executable_path="./chromedriver", chrome_options=chrome_options)
driver.get("https://google.com")
The browser is opened successfully but it doesn't open the specified URL. The URL in the browser is data:,
.
Any help will be greatly appreciated. Please!
Please see the attached image.
Note: Selenium version : 3.14.0
I get the following error on closing the chrome tab.
File "test.py", line 6, in <module>
driver = webdriver.Chrome(executable_path="./chromedriver", chrome_options=chrome_options)
File "/home/speedious/anaconda3/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "/home/speedious/anaconda3/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 156, in __init__
self.start_session(capabilities, browser_profile)
File "/home/speedious/anaconda3/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 251, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/speedious/anaconda3/lib/python3.5/site-packages/selenium/webdriver/remote/webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "/home/speedious/anaconda3/lib/python3.5/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
(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.)
(Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 4.10.0-37-generic x86_64)
Upvotes: 3
Views: 7930
Reputation: 11
If anyone is still having problems, here is what worked for me.
The problem is that chromium gets installed with snap.
So which chromium-browser
terminal command outputs nothing. Nothing is installed at /usr/bin/chromium-browser
.
I tried installing it through sudo apt install chromium-browser
but that didn't fix it.
The solution:
You can then extract this somewhere (for me, it was next to the python script). So my dir now looked like:
In you script, you now set the path to the chrome binary - /your/path/to/chrome-linux64/chrome
.
And this fixed it for me.
Here is my script:
import time
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
# Path to Chromium bin
chromium_path = "./chrome-linux64/chrome" # Replace with the actual path
# Set up Chrome options
chrome_options = Options()
chrome_options.binary_location = chromium_path
url = "https://example.com"
s = Service("./chromedriver_121_0_6167_85")
# Pass the options to the WebDriver
with webdriver.Chrome(service=s, options=chrome_options) as driver:
driver.get(url)
print("Sleeping for 5 seconds...")
time.sleep(5)
Upvotes: 1
Reputation: 1
I found another reason for this behavior, which I don't see listed here. I believe Selenium libraries require Chrome Developer Tools to not be disabled. I was running into this issue and getting this regkey set got me past it.
Key - HKLM\Software\Policies\Google\Chrome
DWORD - DeveloperToolsDisabled
Value - 0
Upvotes: 0
Reputation: 193188
This error message...
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally
(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 instance was unable to start the Chrome Browser process.
Your main issue is the google-chrome is no longer present at the expected default location of /usr/bin/
As per ChromeDriver - Requirements the server expects you to have Chrome installed in the default location for each system:
1 For Linux systems, the ChromeDriver expects /usr/bin/google-chrome to be a symlink to the actual Chrome binary. You can also override the Chrome binary location as follows:
A Windows OS based example:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("start-maximized")
options.binary_location("C:\\path\\to\\chrome.exe")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
driver.get('http://google.com/')
@Test
.Upvotes: 4