8

I am trying to run Selenium on Colab, but an error occurs. It ran well a few weeks ago, but an error occurred suddenly today at the last line of code. What should I do?

!pip install selenium
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
import sys

options = webdriver.ChromeOptions()
options.add_argument('--headless')        
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('chromedriver', options=options)
NaeBo
  • 81
  • 1
  • 5

1 Answers1

0

You need to pass the path to chromedriver in the function. You can use the webdriver_manager library

from webdriver_manager.chrome import ChromeDriverManager
...
...
webdriver.Chrome(ChromeDriverManager().install(), options=options)
Manish
  • 484
  • 3
  • 12
  • 2
    `driver = webdriver.Chrome(ChromeDriverManager().install(), options=options) ` When I changed the code like this, I got this error. `WebDriverException: Message: Service /root/.wdm/drivers/chromedriver/linux64/109.0.5414/chromedriver unexpectedly exited. Status code was: -6` – NaeBo Jan 20 '23 at 01:19
  • It was the same for me. It is hard to figure out the real issue. But it lead to this GitHub request explaining that the reason is the last Ubuntu update that supports chromium diver just via snap. Post with explanation: https://github.com/googlecolab/colabtools/issues/3347#issuecomment-1397277515 You can use this notebook that works to rework your script. It’s basically about the snap installation at the beginning. https://colab.research.google.com/drive/1cbEvuZOhkouYLda3RqiwtbM-o9hxGLyC – Johannes Stephan Jan 21 '23 at 21:32