I have been using selenium chromedriver in google colab for a while.
Today I start my work, I get the error never got before.
I'm wondering if this error is related to the chromedriver version.
This is install log today
!apt-get update
!apt install -y chromium-chromedriver
Get:1 focal-updates/main amd64 apparmor amd64 2.13.3-7ubuntu5.1 [494 kB]
Get:2 focal/main amd64 liblzo2-2 amd64 2.10-2 [50.8 kB]
Get:3 focal-updates/main amd64 squashfs-tools amd64 1:4.4-1ubuntu0.3 [117 kB]
Get:4 focal-updates/main amd64 snapd amd64 2.57.5 20.04ubuntu0.1 [37.6 MB]
Get:5 focal-updates/universe amd64 chromium-browser amd64 1:85.0.4183.83-0ubuntu0.20.04.2 [48.3 kB]
Get:6 focal-updates/universe amd64 chromium-chromedriver amd64 1:85.0.4183.83-0ubuntu0.20.04.2
...
...
(Reading database ... 129791 files and directories currently installed.)
Preparing to unpack .../chromium-browser_1:85.0.4183.83-0ubuntu0.20.04.2_amd64.deb ...
=> Installing the chromium snap
==> Checking connectivity with the snap store
===> System doesn't have a working snapd, skipping
Unpacking chromium-browser (1:85.0.4183.83-0ubuntu0.20.04.2) ...
Selecting previously unselected package chromium-chromedriver.
Preparing to unpack .../chromium-chromedriver_1:85.0.4183.83-0ubuntu0.20.04.2_amd64.deb ...
Unpacking chromium-chromedriver (1:85.0.4183.83-0ubuntu0.20.04.2) ...
Setting up chromium-browser (1:85.0.4183.83-0ubuntu0.20.04.2) ...
update-alternatives: using /usr/bin/chromium-browser to provide /usr/bin/x-www-browser (x-www-browser) in auto mode
update-alternatives: using /usr/bin/chromium-browser to provide /usr/bin/gnome-www-browser (gnome-www-browser) in auto mode
Setting up chromium-chromedriver (1:85.0.4183.83-0ubuntu0.20.04.2) ...
Processing triggers for mime-support (3.64ubuntu1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for libc-bin (2.31-0ubuntu9.9) ...
Processing triggers for systemd (245.4-4ubuntu3.19) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for dbus (1.12.16-2ubuntu2.3) ...
This is install log yesterday
Get:1 bionic-updates/universe amd64 chromium-codecs-ffmpeg-extra amd64 108.0.5359.71-0ubuntu0.18.04.5 [1,159 kB]
Get:2 bionic-updates/universe amd64 chromium-browser amd64 108.0.5359.71-0ubuntu0.18.04.5 [83.6 MB]
Get:3 bionic-updates/universe amd64 chromium-browser-l10n all 108.0.5359.71-0ubuntu0.18.04.5 [5,230 kB]
Get:4 bionic-updates/universe amd64 chromium-chromedriver amd64 108.0.5359.71-0ubuntu0.18.04.5 [5,594 kB]
...
...
Setting up chromium-chromedriver (108.0.5359.71-0ubuntu0.18.04.5) ...
Setting up chromium-browser-l10n (108.0.5359.71-0ubuntu0.18.04.5) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Processing triggers for hicolor-icon-theme (0.17-2) ...
Processing triggers for mime-support (3.60ubuntu1) ...
Processing triggers for libc-bin (2.27-3ubuntu1.6) ...
I found the colab system is updated to ubuntu 20.04 from 18.04.
Is this the reason why chromedriver cannot be used?
How should I do to solve this problem?
Thanks.
CodePudding user response:
Yust checked Selenium with chome using Selenium-Profiles with this script: https://colab.research.google.com/github/kaliiiiiiiiii/Selenium-Profiles/blob/master/google-colab/selenium_profiles.ipynb#scrollTo=P8P_90I2cZXq
And I can confirm, that it doesn't work anymore.
My error code was:
/usr/local/lib/python3.8/dist-packages/selenium_profiles/scripts/profiles.py:112: UserWarning: Might be more likely to get detected with sandbox set to False!
warnings.warn('Might be more likely to get detected with sandbox set to False!')
---------------------------------------------------------------------------
WebDriverException Traceback (most recent call last)
<ipython-input-4-8dcbedddfdca> in <module>
9
10 display.start_display()
---> 11 driver = mydriver.start(profiles.Windows(), uc_driver=False) # or .Android
4 frames
/usr/local/lib/python3.8/dist-packages/selenium_profiles/driver.py in start(self, profile, uc_driver)
82
83 # Actual start of chrome
---> 84 self.driver = webdriver.Chrome(options=self.options) # start selenium webdriver
85
86 self.driver.get('http://motherfuckingwebsite.com/') # wait browser to start
/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, service, keep_alive)
79 service = Service(executable_path, port, service_args, service_log_path)
80
---> 81 super().__init__(
82 DesiredCapabilities.CHROME["browserName"],
83 "goog",
/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chromium/webdriver.py in __init__(self, browser_name, vendor_prefix, port, options, service_args, desired_capabilities, service_log_path, service, keep_alive)
101
102 self.service = service
--> 103 self.service.start()
104
105 try:
/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in start(self)
104 count = 0
105 while True:
--> 106 self.assert_process_still_running()
107 if self.is_connectable():
108 break
/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in assert_process_still_running(self)
117 return_code = self.process.poll()
118 if return_code:
--> 119 raise WebDriverException(f"Service {self.path} unexpectedly exited. Status code was: {return_code}")
120
121 def is_connectable(self) -> bool:
WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1
Also, yesterday it still worked
Usung the script:
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
service = ChromeService(executable_path=ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options = chrome_options)
I still get:
---------------------------------------------------------------------------
WebDriverException Traceback (most recent call last)
<ipython-input-14-7fca8d7963d2> in <module>
9 service = ChromeService(executable_path=ChromeDriverManager().install())
10
---> 11 driver = webdriver.Chrome(service=service, options = chrome_options)
3 frames
/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chrome/webdriver.py in __init__(self, executable_path, port, options, service_args, desired_capabilities, service_log_path, chrome_options, service, keep_alive)
79 service = Service(executable_path, port, service_args, service_log_path)
80
---> 81 super().__init__(
82 DesiredCapabilities.CHROME["browserName"],
83 "goog",
/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chromium/webdriver.py in __init__(self, browser_name, vendor_prefix, port, options, service_args, desired_capabilities, service_log_path, service, keep_alive)
101
102 self.service = service
--> 103 self.service.start()
104
105 try:
/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in start(self)
104 count = 0
105 while True:
--> 106 self.assert_process_still_running()
107 if self.is_connectable():
108 break
/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in assert_process_still_running(self)
117 return_code = self.process.poll()
118 if return_code:
--> 119 raise WebDriverException(f"Service {self.path} unexpectedly exited. Status code was: {return_code}")
120
121 def is_connectable(self) -> bool:
WebDriverException: Message: Service /root/.wdm/drivers/chromedriver/linux64/109.0.5414/chromedriver unexpectedly exited. Status code was: -6
CodePudding user response:
After the runtime status says connected, open the command palette (ctrl shift p) and select "Use Fallback Runtime Version"
That should resolve this issue!
Reference: https://github.com/googlecolab/colabtools/issues/3347#issuecomment-1386349011
We recently upgraded the Ubuntu version, which may be causing this. After connecting to a runtime, can you try running "Use fallback runtime version" from the command palette (ctrl shift p) and seeing if your notebook works after that?