Issue
I am trying to use selenium with some version of Chroium Web Driver. For that I have installed the webdriver_manager
on Debian (WSL 2 on Windows 10 Pro)
pip install webdriver_manager
I have used the lines recommended in the package README
file for selenium 4. I have the version 4.1.5 installed
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.utils import ChromeType
driver = webdriver.Chrome(service=Service(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install()))
But I get this error. I have read that it may be that the selenium version is not compatible with this specific version of the chromedriver, but in the quick reference guide of Selenium, the download version is available the 101.0.4951.41 version. I have installed the latest chrome version and chromedriver for Debian, which is the version 101.0.4951.64 right now. As the webdriver taken is from /home/db/.wdm/drivers/chromedriver/linux64/101.0.4951.41/chromedriver
, and not the installed in the system I don't know if it must match with the chrome version installed in the system. Do they have to match exactly?
This is the error once I run the python script:
====== WebDriver manager ======
Current chromium version is 101.0.4951
Get LATEST chromedriver version for 101.0.4951 chromium
Driver [/home/db/.wdm/drivers/chromedriver/linux64/101.0.4951.41/chromedriver] found in cache
Traceback (most recent call last):
File "/path/to/python/project/webdriver.py", line 21, in <module>
driver = webdriver.Chrome(
File "/path/to/python/project/env/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 70, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "/path/to/python/project/env/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line 92, in __init__
RemoteWebDriver.__init__(
File "/path/to/python/project/env/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 275, in __init__
self.start_session(capabilities, browser_profile)
File "/path/to/python/project/env/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 365, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/path/to/python/project/env/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 430, in execute
self.error_handler.check_response(response)
File "/path/to/python/project/env/lib/python3.9/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
Also, I got this other error:
selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist
And I had to add this code to fix it. But I don't think that will become a problem:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--remote-debugging-port=9222")
driver = webdriver.Chrome(
service=Service(
ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install(),
# executable_path='/usr/bin/chromium'
),
options=chrome_options
)
So I don't know if it's a version related problem or WSL problem. What else can I check?
Solution
Well finally, what solved my problem was to add the flags --no-sandbox
and --headless
to the options object
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--no-sandbox") # without this error > "chrome not found"
chrome_options.add_argument("--headless") # without this error > "chrome not found"
chrome_options.add_argument("--remote-debugging-port=9222")
chrome_options.add_argument("--disable-dev-shm-using")
In spite of that it still give some random behaviour. I think it's due to my slow internet connection inside the WSL system. I was doing some research and I still didn't find any solution. I will post another question to check if anybody knows some workaround.
Answered By - ChesuCR
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.