Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues when trying to use Chromedriver in Colab #3347

Closed
sparent2125 opened this issue Jan 18, 2023 · 56 comments
Closed

Issues when trying to use Chromedriver in Colab #3347

sparent2125 opened this issue Jan 18, 2023 · 56 comments

Comments

@sparent2125
Copy link

sparent2125 commented Jan 18, 2023

I have been running a program for months that uses Selenium in Google Colab. I have not had an issue with it until tonight. Each time I try to run the webdriver, I get the following error:

image

I've also tried running this code:
image

I haven't changed how I install Chromedriver in Colab:
image

This code has been working for months, and I do not know what is causing the error. I'm relatively new to coding, so I'm at wit's end trying to solve this issue.

Edit: I should also add that I've tried a number of different solutions from StackExchange with no success.

@EvanWiederspan
Copy link

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?

@sparent2125
Copy link
Author

@EvanWiederspan thank you so much! That worked! My Notebook stated that I should only use the fallback runtime temporarily and should update my code to work with the current version.

Do you have any idea what changes I would need to make when installing Chromedriver? If not, this solution works for now.

Again, thank you!

@kaliiiiiiiiii
Copy link

kaliiiiiiiiii commented Jan 18, 2023

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?

Didn't wok for me, still got the same error.

Do you have any idea what changes I would need to make when installing Chromedriver?

I think there's something broken with snapd, but not shure:

...

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%3a85.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%3a85.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) ...
...

Maybe try executing chromedriver manually, without selenium? But how would you do that?

Same issue on StackOverflow: https://stackoverflow.com/questions/75155063/selenium-use-chrome-on-colab-got-unexpectedly-exited

@mco-gh
Copy link

mco-gh commented Jan 18, 2023

Weird - your code cell has this statement:

wd = webdriver.chrome(service=Service('/usr/bin/chromedriver',options=options)

but the stack trace shows the same line initializing the Service object with a .exe extension, which is a Windows convention:

wd = webdriver.chrome(service=Service('/usr/bin/chromedriver.exe',options=options)

Can you share a notebook so I can try to reproduce/debug this?

@kaliiiiiiiiii
Copy link

With:

!pip install selenium webdriver_manager
! pip install selenium
!sudo apt-get update
#!sudo apt upgrade snapd
!sudo apt install chromium-chromedriver
!sudo cp /usr/lib/chromium-browser/chromedriver /usr/bin
import sys
sys.path.insert(0,'/usr/lib/chromium-browser/chromedriver')
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(version="108.0.5359.71").install())
service = ChromeService(executable_path=ChromeDriverManager().install())

webdriver.Chrome(service=service, options = chrome_options) # with chromedriver installation Service
#driver = webdriver.Chrome(options = chrome_options)

I'm getting this error: (chromedriver unexpectedly exited. Status code was: -6)

[WDM] - Downloading: 100%|██████████| 6.96M/6.96M [00:00<00:00, 151MB/s]
---------------------------------------------------------------------------
WebDriverException                        Traceback (most recent call last)
[<ipython-input-5-861f141e0929>](https://localhost:8080/#) in <module>
     11 service = ChromeService(executable_path=ChromeDriverManager().install())
     12 
---> 13 webdriver.Chrome(service=service, options = chrome_options) # with chromedriver installation Service
     14 #driver = webdriver.Chrome(options = chrome_options)

3 frames
[/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py](https://localhost:8080/#) 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

usr/bin/chromedriver is:

#!/bin/sh
if ! [ -x /snap/bin/chromium.chromedriver ]; then
    echo "" >&2
    echo "Command '$0' requires the chromium snap to be installed." >&2
    echo "Please install it with:" >&2
    echo "" >&2
    echo "snap install chromium" >&2
    echo "" >&2
    exit 1
fi
exec /snap/bin/chromium.chromedriver "$@"

in this case and retuns WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1

@mco-gh
Copy link

mco-gh commented Jan 18, 2023

I'm happy to take a look if you can share a minimal reproducible notebook but I don't want to copy/paste multiple code fragments into a partially reconstructed version of your notebook.

@kaliiiiiiiiii
Copy link

I'm happy to take a look if you can share a minimal reproducible notebook but I don't want to copy/paste multiple code fragments into a partially reconstructed version of your notebook.

https://colab.research.google.com/drive/1TPVfmjZu1c_sy7QOd9N0XydKzXxeESz2?usp=sharing

@lavarthan
Copy link

@EvanWiederspan using Use fallback runtime version worked for me, But I guess that's a temporary solution. What we should do to run it on the new version?

@mco-gh
Copy link

mco-gh commented Jan 18, 2023

@kaliiiiiiiiii I tried your notebook and it uses ChromeDriverManager to install the Selenium driver, but the version it gives you doesn't work for me. If you instead apt install the driver, as OP does then you should have better results. It still doesn't work with 22.04 but at least the fallback provides a work-around.

@inkazombra
Copy link

Note: I was able to observe this, it seems that the chromium-chromedriver is failing in the current version of ubuntu. Maybe you have to install a previous version of chromium-chromedriver, I hope some expert can help us. In the end we look to use selenium in colab and the fault seems to be in chromium-chromedriver.

(1) before ubuntu 18.04.1
!apt install chromium-chromedriver

Need to get 89.8 MB of archives.
After this operation, 302 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 chromium-codecs-ffmpeg-extra amd64 101.0.4951.64-0ubuntu0.18.04.1 [1,142 kB]
Get:2 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 chromium-browser amd64 101.0.4951.64-0ubuntu0.18.04.1 [78.5 MB]
Get:3 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 chromium-browser-l10n all 101.0.4951.64-0ubuntu0.18.04.1 [4,980 kB]
Get:4 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 chromium-chromedriver amd64 101.0.4951.64-0ubuntu0.18.04.1 [5,153 kB]
Fetched 89.8 MB in 3s (26.3 MB/s)

(2) now ubuntu 20.04.2
!apt install chromium-chromedriver
Need to get 38.4 MB of archives.
After this operation, 173 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 apparmor amd64 2.13.3-7ubuntu5.1 [494 kB]
Get:2 http://archive.ubuntu.com/ubuntu focal/main amd64 liblzo2-2 amd64 2.10-2 [50.8 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 squashfs-tools amd64 1:4.4-1ubuntu0.3 [117 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 snapd amd64 2.57.5+20.04ubuntu0.1 [37.6 MB]
Get:5 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 chromium-browser amd64 1:85.0.4183.83-0ubuntu0.20.04.2 [48.3 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 chromium-chromedriver amd64 1:85.0.4183.83-0ubuntu0.20.04.2 [2,496 B]
Fetched 38.4 MB in 3s (14.8 MB/s)

@metrizable
Copy link
Contributor

Thanks for using Colab. I understand that you'd like to use selenium with chromium-browser under Ubuntu 20.04 LTS. Although YMMV, since Ubuntu 20.04+ no longer distributes chromium-browser outside of a snap package, you can install a compatible version from the Debian buster repository:

%%shell
# Ubuntu no longer distributes chromium-browser outside of snap
#
# Proposed solution: https://askubuntu.com/questions/1204571/how-to-install-chromium-without-snap

# Add debian buster
cat > /etc/apt/sources.list.d/debian.list <<'EOF'
deb [arch=amd64 signed-by=/usr/share/keyrings/debian-buster.gpg] http://deb.debian.org/debian buster main
deb [arch=amd64 signed-by=/usr/share/keyrings/debian-buster-updates.gpg] http://deb.debian.org/debian buster-updates main
deb [arch=amd64 signed-by=/usr/share/keyrings/debian-security-buster.gpg] http://deb.debian.org/debian-security buster/updates main
EOF

# Add keys
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DCC9EFBF77E11517
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 112695A0E562B32A

apt-key export 77E11517 | gpg --dearmour -o /usr/share/keyrings/debian-buster.gpg
apt-key export 22F3D138 | gpg --dearmour -o /usr/share/keyrings/debian-buster-updates.gpg
apt-key export E562B32A | gpg --dearmour -o /usr/share/keyrings/debian-security-buster.gpg

# Prefer debian repo for chromium* packages only
# Note the double-blank lines between entries
cat > /etc/apt/preferences.d/chromium.pref << 'EOF'
Package: *
Pin: release a=eoan
Pin-Priority: 500


Package: *
Pin: origin "deb.debian.org"
Pin-Priority: 300


Package: chromium*
Pin: origin "deb.debian.org"
Pin-Priority: 700
EOF

# Install chromium and chromium-driver
apt-get update
apt-get install chromium chromium-driver

# Install selenium
pip install selenium

I was able to successfully invoke selenium after this install:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

url = "<url>" 
options = Options()
options.add_argument("--headless")
options.add_argument("--no-sandbox")

options.headless = True

driver = webdriver.Chrome("/usr/bin/chromedriver", options=options)

driver.get(url)
print(driver.title)
driver.quit()

@Kaartik777
Copy link

@kaliiiiiiiiii I tried your notebook and it uses ChromeDriverManager to install the Selenium driver, but the version it gives you doesn't work for me. If you instead apt install the driver, as OP does then you should have better results. It still doesn't work with 22.04 but at least the fallback provides a work-around.

I tried to run using the OP's method but can't understand how to do. Can you please add what changes in OP's code is required to "apt install the driver"?
I tried this in fallback runtime but not working- https://colab.research.google.com/drive/1Z0lZdllyToLEjQm8Lna47ZEZRVkIS3HP?usp=sharing

@mco-gh
Copy link

mco-gh commented Jan 19, 2023

Check @metrizable's comment above, just before yours, I think it has everything you need.

@Kaartik777
Copy link

Check @metrizable's comment above, just before yours, I think it has everything you need.

I tried pasting the code but the "apt-get install chromium chromium-driver" fails and showing -

Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
chromium : Depends: libavcodec58 (>= 7:4.0)
Depends: libavformat58 (>= 7:4.1) but it is not going to be installed
Depends: libavutil56 (>= 7:4.0) but it is not going to be installed
Depends: libc6 (>= 2.28) but 2.27-3ubuntu1.6 is to be installed
Depends: libharfbuzz0b (>= 2.2.0) but 1.7.2-1ubuntu1 is to be installed
Recommends: chromium-sandbox but it is not going to be installed
chromium-driver : Depends: libc6 (>= 2.28) but 2.27-3ubuntu1.6 is to be installed
E: Unable to correct problems, you have held broken packages

and it fails saying

"Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home"

colab link - https://colab.research.google.com/drive/12WRdjK2OOdMb-WV2csHk1kUWXcmHtbFz?usp=sharing

on replacing "apt-get install chromium chromium-driver" with "!apt install chromium-chromedriver" it again gives
"Message: Service /usr/bin/chromedriver unexpectedly exited. Status code was: -6"

Sorry if I did any novice thing as I am new to coding and linux.

I would really appreciate if anyone can provide a working colab file with webdriver instance.

@mco-gh
Copy link

mco-gh commented Jan 19, 2023

I just created a new notebook following @metrizable's guidance and it worked fine for me. Here's a reference: https://colab.research.google.com/drive/1cbEvuZOhkouYLda3RqiwtbM-o9hxGLyC

@Kaartik777
Copy link

Kaartik777 commented Jan 19, 2023

I just created a new notebook following @metrizable's guidance and it worked fine for me. Here's a reference: https://colab.research.google.com/drive/1cbEvuZOhkouYLda3RqiwtbM-o9hxGLyC

Thank you very much now it somehow works for me too! Thanks @mco-gh and @metrizable.

@gtpeter
Copy link

gtpeter commented Jan 23, 2023

Don't know why my notebook is still under Ubuntu 18.04 LTS (screenshot-1), but chromedriver is NOT working with Status Code: -6, Previously the Status Code was: 1 (about > 1 week ago), In fact, earlier this week it suddenly worked as normal, but now error Status Code again, Only diff is 1 became -6.

Using @metrizable method, it created "unmet dependencies" error (screenshot-2) in 18.04. After duplicated the notebook, the environment is 20.04, and all work with @metrizable's method. Kudos to him !

image
image

@kaliiiiiiiiii
Copy link

kaliiiiiiiiii commented Jan 23, 2023

@gtpeter You might try excuting:

sudo apt update; sudo apt upgrade

And then use @metrizable his method?

Or try using a google-colab link provided in this thread.

@user-2608
Copy link

service_log_path, chrome_options, service, keep_alive)
78 service = Service(executable_path, port, service_args, service_log_path)
79
---> 80 super().init(
81 DesiredCapabilities.CHROME["browserName"],
82 "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)
99
100 self.service = service
--> 101 self.service.start()
102
103 try:

/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in start(self)
102 count = 0
103 while True:
--> 104 self.assert_process_still_running()
105 if self.is_connectable():
106 break

/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in assert_process_still_running(self)
115 return_code = self.process.poll()
116 if return_code:
--> 117 raise WebDriverException(f"Service {self.path} unexpectedly exited. Status code was: {return_code}")
118
119 def is_connectable(self) -> bool:

WebDriverException: Message: Service /usr/bin/chromedriver unexpectedly exited. Status code was: 1

@user-2608
Copy link

service_log_path, chrome_options, service, keep_alive) 78 service = Service(executable_path, port, service_args, service_log_path) 79 ---> 80 super().init( 81 DesiredCapabilities.CHROME["browserName"], 82 "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) 99 100 self.service = service --> 101 self.service.start() 102 103 try:

/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in start(self) 102 count = 0 103 while True: --> 104 self.assert_process_still_running() 105 if self.is_connectable(): 106 break

/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in assert_process_still_running(self) 115 return_code = self.process.poll() 116 if return_code: --> 117 raise WebDriverException(f"Service {self.path} unexpectedly exited. Status code was: {return_code}") 118 119 def is_connectable(self) -> bool:

WebDriverException: Message: Service /usr/bin/chromedriver unexpectedly exited. Status code was: 1

i am also facing similar issue tried thecolab-notebook option but it is not working.

@gtpeter
Copy link

gtpeter commented Jan 25, 2023

@gtpeter You might try excuting:

sudo apt update; sudo apt upgrade

And then use @metrizable his method?

Or try using a google-colab link provided in this thread.

Hi, @kaliiiiiiiiii , Thanks for your suggestions.

Today, I noted that my old notebook (used to be 18.04 LTS), also changed to 20.04 LTS already. So I can't try your suggestion (as everything is working fine with @metrizable method inside 20.04 LTS). My old notebook does have command "sudo apt update" (can' t remember if I ever tried "sudo apt upgrade"), However, it didn't work in 18.04 LTS (2 days ago)

Anyway, Thanks for your suggestion. we should all stick to 20.04 LTS now ! 😄

@gtpeter
Copy link

gtpeter commented Jan 25, 2023

service_log_path, chrome_options, service, keep_alive) 78 service = Service(executable_path, port, service_args, service_log_path) 79 ---> 80 super().init( 81 DesiredCapabilities.CHROME["browserName"], 82 "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) 99 100 self.service = service --> 101 self.service.start() 102 103 try:
/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in start(self) 102 count = 0 103 while True: --> 104 self.assert_process_still_running() 105 if self.is_connectable(): 106 break
/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in assert_process_still_running(self) 115 return_code = self.process.poll() 116 if return_code: --> 117 raise WebDriverException(f"Service {self.path} unexpectedly exited. Status code was: {return_code}") 118 119 def is_connectable(self) -> bool:
WebDriverException: Message: Service /usr/bin/chromedriver unexpectedly exited. Status code was: 1

i am also facing similar issue tried thecolab-notebook option but it is not working.

Make sure your environment is 20.04 LTS, and tried again with @metrizable method !

@asudakov
Copy link

asudakov commented Jan 26, 2023

WebDriverException: Message: Service /usr/bin/chromedriver unexpectedly exited. Status code was: 1

i am also facing similar issue tried thecolab-notebook option but it is not working.

Make sure your environment is 20.04 LTS, and tried again with @metrizable method !

I am having the same issue. I just created fresh Notebook, since linked Notebook is gone, and added @metrizable code. I am getting same "Status code was: 1".

cat /etc/os-release shows

NAME="Ubuntu"
VERSION="20.04.5 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.5 LTS"
VERSION_ID="20.04"

@gtpeter
Copy link

gtpeter commented Jan 27, 2023

WebDriverException: Message: Service /usr/bin/chromedriver unexpectedly exited. Status code was: 1

i am also facing similar issue tried thecolab-notebook option but it is not working.

Make sure your environment is 20.04 LTS, and tried again with @metrizable method !

I am having the same issue. I just created fresh Notebook, since linked Notebook is gone, and added @metrizable code. I am getting same "Status code was: 1".

cat /etc/os-release shows

NAME="Ubuntu" VERSION="20.04.5 LTS (Focal Fossa)" ID=ubuntu ID_LIKE=debian PRETTY_NAME="Ubuntu 20.04.5 LTS" VERSION_ID="20.04"

FYI, I am not a programmer, just a copy-cat, so I don't know how to debug. I just ran the codes, all still worked as expected.

Can troubleshoot the problem as below:

  1. @metrizable 's code in the FIRST (Top-Most) Cell, with no other code in front or on top of %%Shell. I ever failed the code , because there were other code on top of the @metrizable's code (within the same cell).
  2. Copy following code in the 2nd Cell (without dash lines). See if it can pass with output "Example Domain"
  3. (Please remove any other codes and Cells in the notebook)
  4. I believe the command "!apt-get update" might be important. It produces error: -6 if this command is not added.

!apt-get update
!apt-get install chromium chromium-driver
!pip3 install selenium

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

url = "http://example.com"
options = Options()
options.add_argument("--headless")
options.add_argument("--no-sandbox")
driver = webdriver.Chrome("chromedriver", options=options)

driver.get(url)
print(driver.title)
driver.quit()


@Kajal2000kk
Copy link

I just created a new notebook following @metrizable's guidance and it worked fine for me. Here's a reference: https://colab.research.google.com/drive/1cbEvuZOhkouYLda3RqiwtbM-o9hxGLyC

hii its showing page not found can you able to give solution

@vr00n
Copy link

vr00n commented Feb 8, 2023

Same - the code with the resolution no longer work.

@metrizable
Copy link
Contributor

I tried the code from the comment above and it functioned correctly for me, although there were deprecation warnings. I went ahead and updated the last cell with the following code to no longer use deprecated code paths, which eliminated the warnings:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

url = "http://example.com"

service = Service("/usr/bin/chromedriver")

options = Options()
options.add_argument("--headless")
options.add_argument("--no-sandbox")

driver = webdriver.Chrome(service=service, options=options)

driver.get(url)
print(driver.title)
driver.quit()

BiTjTMvKMaVUvG9

@gtpeter
Copy link

gtpeter commented Feb 9, 2023

Just tested, it looks still working.
I ran the notebook 4 times, only very 1st time failed due to different error (I guess it might be related to slow connection / downloading of package??). The subsequent 3 times (with runtime deleted) all work as normal, except a bit slow connection than before.

@vr00n
Copy link

vr00n commented Feb 14, 2023

Confirmed! Thanks @metrizable.
First time I ran it, the code was in a hung state but when trying again, it worked.

@guiworldtv2
Copy link

!pip install chromium
!/usr/bin/chromedriver --version

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

url = "http://www.google.com"

service = Service("/usr/bin/chromedriver")

options = Options()
options.add_argument("--headless")
options.add_argument("--no-sandbox")

driver = webdriver.Chrome(service=service, options=options)

driver.get(url)
print(driver.title)
driver.quit() Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/
ERROR: Could not find a version that satisfies the requirement chromium (from versions: none)
ERROR: No matching distribution found for chromium

Command '/usr/bin/chromedriver' requires the chromium snap to be installed.
Please install it with:

snap install chromium


WebDriverException Traceback (most recent call last)

in
14 options.add_argument("--no-sandbox")
15
---> 16 driver = webdriver.Chrome(service=service, options=options)
17
18 driver.get(url)

3 frames

/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in assert_process_still_running(self)
115 return_code = self.process.poll()
116 if return_code:
--> 117 raise WebDriverException(f"Service {self.path} unexpectedly exited. Status code was: {return_code}")
118
119 def is_connectable(self) -> bool:

WebDriverException: Message: Service /usr/bin/chromedriver unexpectedly exited. Status code was: 1

@Nothig00
Copy link

Nothig00 commented Mar 25, 2023

How to add extension ?

Error

extension File https://github.com/Nothig00/resources/raw/main/Metamask.crx

Code

options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_extension('Metamask.crx')
options.page_load_strategy = 'eager'
driver = webdriver.Chrome(options=options)

driver.get("chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html#onboarding/import-with-recovery-phrase")

print('finish')

@tiendu
Copy link

tiendu commented Apr 16, 2023

I was able to do it by downloading the correct version of chromedriver. Since the version of chromium is 90, so we have to get the correct chromedriver for it too.

We need to run this first.

%%shell

# Add debian buster
cat > /etc/apt/sources.list.d/debian.list <<'EOF'
deb [arch=amd64 signed-by=/usr/share/keyrings/debian-buster.gpg] http://deb.debian.org/debian buster main
deb [arch=amd64 signed-by=/usr/share/keyrings/debian-buster-updates.gpg] http://deb.debian.org/debian buster-updates main
deb [arch=amd64 signed-by=/usr/share/keyrings/debian-security-buster.gpg] http://deb.debian.org/debian-security buster/updates main
EOF

# Add keys
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DCC9EFBF77E11517
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 112695A0E562B32A

apt-key export 77E11517 | gpg --dearmour -o /usr/share/keyrings/debian-buster.gpg
apt-key export 22F3D138 | gpg --dearmour -o /usr/share/keyrings/debian-buster-updates.gpg
apt-key export E562B32A | gpg --dearmour -o /usr/share/keyrings/debian-security-buster.gpg

# Prefer debian repo for chromium* packages only
# Note the double-blank lines between entries
cat > /etc/apt/preferences.d/chromium.pref << 'EOF'
Package: *
Pin: release a=eoan
Pin-Priority: 500


Package: *
Pin: origin "deb.debian.org"
Pin-Priority: 300


Package: chromium*
Pin: origin "deb.debian.org"
Pin-Priority: 700
EOF

Then download the correct chromedriver.

!wget https://chromedriver.storage.googleapis.com/90.0.4430.24/chromedriver_linux64.zip
!unzip chromedriver_linux64.zip
!chmod 777 chromedriver
!mv chromedriver /usr/bin/

Afterwards, I was able to run the following cell.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

url = "http://example.com"

service = Service("/usr/bin/chromedriver")

options = Options()
options.add_argument("--headless")
options.add_argument("--no-sandbox")

driver = webdriver.Chrome(service=service, options=options)

driver.get(url)
print(driver.title)
driver.quit()

@kaliiiiiiiiii
Copy link

I was able to do it by downloading the correct version of chromedriver. Since the version of chromium is 90, so we have to get the correct chromedriver for it too.

Exactly, or you can use webdriver-manager

# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager(version="90.0.4430.24").install()))

@Nothig00
Copy link

I was able to do it by downloading the correct version of chromedriver. Since the version of chromium is 90, so we have to get the correct chromedriver for it too.

Exactly, or you can use webdriver-manager

# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager(version="90.0.4430.24").install()))

I'm asking you because I don't get any solution or any conclusion on this thing #3347 (comment)

So can plz tell me how to add extension

@kaliiiiiiiiii
Copy link

How to add extension ?

Error

extension File https://github.com/Nothig00/resources/raw/main/Metamask.crx

Code

options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_extension('Metamask.crx')
options.page_load_strategy = 'eager'
driver = webdriver.Chrome(options=options)

driver.get("chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html#onboarding/import-with-recovery-phrase")

print('finish')

Did you try that locally? If not, maybe move this question to a non-google-colab specific discusstion

@Nothig00
Copy link

How to add extension ?
Error
extension File https://github.com/Nothig00/resources/raw/main/Metamask.crx
Code

options = Options()
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_extension('Metamask.crx')
options.page_load_strategy = 'eager'
driver = webdriver.Chrome(options=options)

driver.get("chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/home.html#onboarding/import-with-recovery-phrase")

print('finish')

Did you try that locally? If not, maybe move this question to a non-google-colab specific discusstion

Here a notebook
https://colab.research.google.com/drive/1mkZyhqM6jLS9cUCGd3j7HqIs7xzAfOdF?usp=sharing

really I tried so hard but no solution have come so please... Help me

@RudRho
Copy link

RudRho commented Apr 25, 2023

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?

to update on April 25, 2023 – 12:54
this works for me too. could you pls see to this and correct for this

@goljavi
Copy link

goljavi commented May 7, 2023

Hi! i found a solution on this website: https://dev.classmethod.jp/articles/google-colaboratory-use-selenium/

They start on a fresh google colab and then run the next code block:

%%shell
sudo apt -y update
sudo apt install -y wget curl unzip
wget http://archive.ubuntu.com/ubuntu/pool/main/libu/libu2f-host/libu2f-udev_1.1.4-1_all.deb
dpkg -i libu2f-udev_1.1.4-1_all.deb
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i google-chrome-stable_current_amd64.deb
CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`
wget -N https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -P /tmp/
unzip -o /tmp/chromedriver_linux64.zip -d /tmp/
chmod +x /tmp/chromedriver
mv /tmp/chromedriver /usr/local/bin/chromedriver
pip install selenium

Then they run selenium as normal:

from selenium import webdriver

URL = "https://google.com"

options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--no-sandbox")

driver = webdriver.Chrome(
    options=options
)

driver.get(URL)
title = driver.title
driver.close()

print(title)

It worked for me! hope this helps

@barryliu2000
Copy link

good!

@nathanaelvictorious
Copy link

Hi! i found a solution on this website: https://dev.classmethod.jp/articles/google-colaboratory-use-selenium/

They start on a fresh google colab and then run the next code block:

%%shell
sudo apt -y update
sudo apt install -y wget curl unzip
wget http://archive.ubuntu.com/ubuntu/pool/main/libu/libu2f-host/libu2f-udev_1.1.4-1_all.deb
dpkg -i libu2f-udev_1.1.4-1_all.deb
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i google-chrome-stable_current_amd64.deb
CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`
wget -N https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -P /tmp/
unzip -o /tmp/chromedriver_linux64.zip -d /tmp/
chmod +x /tmp/chromedriver
mv /tmp/chromedriver /usr/local/bin/chromedriver
pip install selenium

Then they run selenium as normal:

from selenium import webdriver

URL = "https://google.com"

options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--no-sandbox")

driver = webdriver.Chrome(
    options=options
)

driver.get(URL)
title = driver.title
driver.close()

print(title)

It worked for me! hope this helps

This code still working for people trying to use Selenium on Google Colab per 21th June 2023

@nithincp
Copy link

nithincp commented Jul 9, 2023

Hi! i found a solution on this website: https://dev.classmethod.jp/articles/google-colaboratory-use-selenium/
They start on a fresh google colab and then run the next code block:

%%shell
sudo apt -y update
sudo apt install -y wget curl unzip
wget http://archive.ubuntu.com/ubuntu/pool/main/libu/libu2f-host/libu2f-udev_1.1.4-1_all.deb
dpkg -i libu2f-udev_1.1.4-1_all.deb
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i google-chrome-stable_current_amd64.deb
CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`
wget -N https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -P /tmp/
unzip -o /tmp/chromedriver_linux64.zip -d /tmp/
chmod +x /tmp/chromedriver
mv /tmp/chromedriver /usr/local/bin/chromedriver
pip install selenium

Then they run selenium as normal:

from selenium import webdriver

URL = "https://google.com"

options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--no-sandbox")

driver = webdriver.Chrome(
    options=options
)

driver.get(URL)
title = driver.title
driver.close()

print(title)

It worked for me! hope this helps

This code still working for people trying to use Selenium on Google Colab per 21th June 2023

The above solution worked for me. Thank You

@FDSRashid
Copy link

FDSRashid commented Aug 17, 2023

Hi! i found a solution on this website: https://dev.classmethod.jp/articles/google-colaboratory-use-selenium/
They start on a fresh google colab and then run the next code block:

%%shell
sudo apt -y update
sudo apt install -y wget curl unzip
wget http://archive.ubuntu.com/ubuntu/pool/main/libu/libu2f-host/libu2f-udev_1.1.4-1_all.deb
dpkg -i libu2f-udev_1.1.4-1_all.deb
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i google-chrome-stable_current_amd64.deb
CHROME_DRIVER_VERSION=`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`
wget -N https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip -P /tmp/
unzip -o /tmp/chromedriver_linux64.zip -d /tmp/
chmod +x /tmp/chromedriver
mv /tmp/chromedriver /usr/local/bin/chromedriver
pip install selenium

Then they run selenium as normal:

from selenium import webdriver

URL = "https://google.com"

options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--no-sandbox")

driver = webdriver.Chrome(
    options=options
)

driver.get(URL)
title = driver.title
driver.close()

print(title)

It worked for me! hope this helps

This code still working for people trying to use Selenium on Google Colab per 21th June 2023

The above solution worked for me. Thank You

Hi all,
the code here almost works perfectly. As of 8/16 , the following lines will not work because the latest driver for chrome has moved locations:
CHROME_DRIVER_VERSION=curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE wget -N https://chromedriver.storage.googleapis.com/$CHROME_DRIVER_VERSION/chromedriver_linux64.zip

However, i was able to locate the new Chrome Driver with the following line of code wget -N https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chromedriver-linux64.zip

The link to the new chrome drivers are here, in case new driver versions get uploaded : https://googlechromelabs.github.io/chrome-for-testing/

All you have to do the replace wget line, keeping everything else after the 'zip' part. The code should work as normal. I hope this works for everyone!

@gtpeter
Copy link

gtpeter commented Aug 18, 2023

The unzip and move folder command may need to change slightly due to different zip file name and its subfolder inside the new zip file

unzip -o /tmp/chromedriver-linux64.zip -d /tmp/
// the under_score became dash "-"

chmod +x /tmp/chromedriver-linux64/chromedriver
// subfolder named "chromedriver-linux64"

mv /tmp/chromedriver-linux64/chromedriver /usr/local/bin/chromedriver
// subfolder named "chromedriver-linux64"

@fanpeeps
Copy link

fanpeeps commented Aug 20, 2023

Folks, myself included, are having similar problems running Firefox (with Geckodriver) in collab.

Primary problem is overcoming the following error:

"InvalidArgumentException: Message: binary is not a Firefox executable"

Is there a similar work-around for Firefox users?

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service

options = Options()
options.binary = '/usr/bin/firefox'
options.binary_location = "/usr/bin/firefox" 
options.add_argument("--headless")
options.add_argument('start-maximized')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')

service = Service(executable_path='/usr/bin/geckodriver')

driver = webdriver.Firefox(options=options, service=service)
driver.get("https://www.google.com")
print(driver.title)
driver.quit()

Produces error:
"InvalidArgumentException: Message: binary is not a Firefox executable"

@fanpeeps
Copy link

wget -N https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chromedriver-linux64.zip

2023-08-20 23:24:09 (147 MB/s) - ‘google-chrome-stable_current_amd64.deb’ saved [96765132/96765132]

Selecting previously unselected package google-chrome-stable.
(Reading database ... 120835 files and directories currently installed.)
Preparing to unpack google-chrome-stable_current_amd64.deb ...
Unpacking google-chrome-stable (116.0.5845.96-1) ...
dpkg: dependency problems prevent configuration of google-chrome-stable:
google-chrome-stable depends on libvulkan1; however:
Package libvulkan1 is not installed.

Nope:

dpkg: error processing package google-chrome-stable (--install):
dependency problems - leaving unconfigured
Processing triggers for man-db (2.10.2-1) ...
Errors were encountered while processing:
google-chrome-stable
--2023-08-20 23:24:21-- https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chromedriver-linux64.zip
Resolving edgedl.me.gvt1.com (edgedl.me.gvt1.com)... 34.104.35.123, 2600:1900:4110:86f::
Connecting to edgedl.me.gvt1.com (edgedl.me.gvt1.com)|34.104.35.123|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7271942 (6.9M) [application/octet-stream]
Saving to: ‘chromedriver-linux64.zip’

@hanahiroAze
Copy link

%%shell
sudo apt -y update
sudo apt install -y wget curl unzip
wget http://archive.ubuntu.com/ubuntu/pool/main/libu/libu2f-host/libu2f-udev_1.1.4-1_all.deb
dpkg -i libu2f-udev_1.1.4-1_all.deb

# install Chrome
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
dpkg -i google-chrome-stable_current_amd64.deb

# install Chrome Driver
wget -N https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chromedriver-linux64.zip -P /tmp/
unzip -o /tmp/chromedriver-linux64.zip -d /tmp/
chmod +x /tmp/chromedriver-linux64/chromedriver
mv /tmp/chromedriver-linux64/chromedriver /usr/local/bin/chromedriver

and

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path=r'/usr/local/bin/chromedriver')
options = webdriver.ChromeOptions()
options.binary_location = r'/usr/local/bin/chromedriver'
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--remote-debugging-port=9222") 
options.add_argument('--disable-features=VizDisplayCompositor')

driver = webdriver.Chrome(service=service, options=options)

at here

---------------------------------------------------------------------------
WebDriverException                        Traceback (most recent call last)
[<ipython-input-96-057af7835017>](https://localhost:8080/#) in <cell line: 21>()
     19 options.add_argument('--disable-features=VizDisplayCompositor')
     20 
---> 21 driver = webdriver.Chrome(service=service, options=options)
     22 driver.implicitly_wait(10)
     23 

5 frames
[/usr/local/lib/python3.10/dist-packages/selenium/webdriver/remote/errorhandler.py](https://localhost:8080/#) in check_response(self, response)
    227                     for frame in st_value:
    228                         line = self._value_or_default(frame, 'lineNumber', '')
--> 229                         file = self._value_or_default(frame, 'fileName', '<anonymous>')
    230                         if line:
    231                             file = "%s:%s" % (file, line)

WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (chrome not reachable)
  (The process started from chrome location /usr/local/bin/chromedriver is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
#0 0x588518b49e23 <unknown>
#1 0x5885188727a7 <unknown>
#2 0x58851889d50a <unknown>
#3 0x58851889aa25 <unknown>
#4 0x5885188dad92 <unknown>
#5 0x5885188da3af <unknown>
#6 0x5885188d1de3 <unknown>
#7 0x5885188a5a7b <unknown>
#8 0x5885188a681e <unknown>
#9 0x588518b0b638 <unknown>
#10 0x588518b0f507 <unknown>
#11 0x588518b19c4c <unknown>
#12 0x588518b10136 <unknown>
#13 0x588518ade9cf <unknown>
#14 0x588518b33b98 <unknown>
#15 0x588518b33d68 <unknown>
#16 0x588518b42cb3 <unknown>
#17 0x7c3c310c9b43 <unknown>

@AycaCicek
Copy link

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

service = Service(executable_path=r'/usr/local/bin/chromedriver')
options = webdriver.ChromeOptions()
options.binary_location = r'/usr/local/bin/chromedriver'
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--remote-debugging-port=9222")
options.add_argument('--disable-features=VizDisplayCompositor')

driver = webdriver.Chrome(service=service, options=options)

change the above part to:

from selenium import webdriver

URL = "https://dev.classmethod.jp/"

options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--no-sandbox")

driver = webdriver.Chrome(
options=options
)

It work for me.

@hanahiroAze
Copy link

it was due to chrome driver after ver.115

!sudo apt -y update
!rm -f *.deb
!sudo apt install -y wget curl unzip libvulkan1
!wget http://archive.ubuntu.com/ubuntu/pool/main/libu/libu2f-host/libu2f-udev_1.1.4-1_all.deb
!dpkg -i libu2f-udev_1.1.4-1_all.deb

!wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
!dpkg -i google-chrome-stable_current_amd64.deb

!rm -rf /tmp/*
!wget -N https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/116.0.5845.96/linux64/chromedriver-linux64.zip -P /tmp/
!unzip -o /tmp/chromedriver-linux64.zip -d /tmp/
!cp -rf /tmp/chromedriver-linux64 /tmp/chromedriver
!chmod +x /tmp/chromedriver/chromedriver
!mv /tmp/chromedriver/chromedriver /usr/local/bin/chromedriver

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys

URL = "URL"

options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--no-sandbox")

driver = webdriver.Chrome(
    options=options
)

driver.maximize_window()
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
driver.get(URL)

@DracoCoder
Copy link

I was able to do it by downloading the correct version of chromedriver. Since the version of chromium is 90, so we have to get the correct chromedriver for it too.

We need to run this first.

%%shell

# Add debian buster
cat > /etc/apt/sources.list.d/debian.list <<'EOF'
deb [arch=amd64 signed-by=/usr/share/keyrings/debian-buster.gpg] http://deb.debian.org/debian buster main
deb [arch=amd64 signed-by=/usr/share/keyrings/debian-buster-updates.gpg] http://deb.debian.org/debian buster-updates main
deb [arch=amd64 signed-by=/usr/share/keyrings/debian-security-buster.gpg] http://deb.debian.org/debian-security buster/updates main
EOF

# Add keys
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DCC9EFBF77E11517
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 112695A0E562B32A

apt-key export 77E11517 | gpg --dearmour -o /usr/share/keyrings/debian-buster.gpg
apt-key export 22F3D138 | gpg --dearmour -o /usr/share/keyrings/debian-buster-updates.gpg
apt-key export E562B32A | gpg --dearmour -o /usr/share/keyrings/debian-security-buster.gpg

# Prefer debian repo for chromium* packages only
# Note the double-blank lines between entries
cat > /etc/apt/preferences.d/chromium.pref << 'EOF'
Package: *
Pin: release a=eoan
Pin-Priority: 500


Package: *
Pin: origin "deb.debian.org"
Pin-Priority: 300


Package: chromium*
Pin: origin "deb.debian.org"
Pin-Priority: 700
EOF

Then download the correct chromedriver.

!wget https://chromedriver.storage.googleapis.com/90.0.4430.24/chromedriver_linux64.zip
!unzip chromedriver_linux64.zip
!chmod 777 chromedriver
!mv chromedriver /usr/bin/

Afterwards, I was able to run the following cell.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service

url = "http://example.com"

service = Service("/usr/bin/chromedriver")

options = Options()
options.add_argument("--headless")
options.add_argument("--no-sandbox")

driver = webdriver.Chrome(service=service, options=options)

driver.get(url)
print(driver.title)
driver.quit()

Thank you so much this worked for me on colab

@SanketAdamapure
Copy link

https://colab.research.google.com/drive/17LXBjJ5KZxy5Mj3Os7ZQa9VAV4DDJzxP?usp=sharing

This is my sample notebook link, NOT the original link, which is down.

I Tried this code But it's showing this error
TypeError: WebDriver.init() got multiple values for argument 'options'

@jpjacobpadilla
Copy link

jpjacobpadilla commented Nov 11, 2023

I made this thin wrapper around Selenium (ChromeDriver) which makes it easy to use Selenium in Google Colab Notebooks!

https://github.com/jpjacobpadilla/Google-Colab-Selenium

You just PIP install the package and then can use Selenium like this In Google Colab:

import google_colab_selenium as gs

driver = gs.ChromeDriver()
# Your code to interact with the driver here
driver.quit()

The package installs and sets up Google Chrome and ChromeDriver as well as adds 4 default headers ("--headless", "--no-sandbox", "--disable-dev-shm-usage", and "--lang=en".

@CarlaArchuleta01
Copy link

I have been running a program for months that uses Selenium in Google Colab. I have not had an issue with it until tonight. Each time I try to run the webdriver, I get the following error:

image

I've also tried running this code: image

I haven't changed how I install Chromedriver in Colab: image

This code has been working for months, and I do not know what is causing the error. I'm relatively new to coding, so I'm at wit's end trying to solve this issue.

Edit: I should also add that I've tried a number of different solutions from StackExchange with no success.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests