skip to Main Content

I have been using selenium chromedriver in google colab for the past year and it seems to be working perfectly.

But last week, the script doesnt seem to be working anymore. I looked at the python version of google colab and it’s now on python 3.8.16 which I think is the culprit of this code breaking.

I use the code:

!pip install selenium
!apt-get update # to update ubuntu to correctly run apt install
!apt install -y chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin

from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver= webdriver.Chrome('chromedriver',options=chrome_options)`

And now in this line:
driver= webdriver.Chrome(‘chromedriver’,options=chrome_options)

I get an error saying:
WebDriverException: Message: Service chromedriver unexpectedly exited. Status code was: 1

Anyone already found a fix for this?

2

Answers


  1. Seems to be a problem with chromedriver itsself, and not python.

    Also, I couldn’t reproduce the error.
    Seems to be fine

    The execution seems to be fine for me.

    You might check, if there’s something else in your code which might break it and you didn’t provide here.

    Login or Signup to reply.
  2. Run This Codes. For me it Worked

    %%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
    

    Then Run This

    !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()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search