Home > Software engineering >  Why did Selenium stop working today on Colab?
Why did Selenium stop working today on Colab?

Time:05-07

Screen Shot

Link to workbook showing issue:`

https://colab.research.google.com/drive/1Zf8YTHRLOL6-ez1SWvzZEVZpkelrG2Kz?usp=sharing

!apt-get update
!apt install chromium-chromedriver
!pip install selenium
from selenium import webdriver

Google Colab Account on Chrome Browserenter image description here

I have run various scripts for the last two years and no issues.

Today I get the following error:

ImportError: cannot import name 'Literal' from 'typing' (/usr/lib/python3.7/typing.py)


CodePudding user response:

The error relates to the typing library. I do not know exactly why this is happening and I hope someone has a better solution than mine, but editing the file that calls this library worked for me:

# Install Normal Selenium Stuff

!pip install selenium
!apt-get update # to update ubuntu to correctly run apt install
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
import sys
sys.path.insert(0,'/usr/lib/chromium-browser/chromedriver')

## This edits the part of the file that gives the error:

with open('/usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/virtual_authenticator.py', 'r') as file:
  
    # read a list of lines into data
    data = file.readlines()

data[21] = 'from typing_extensions import Literal\n'

with open('/usr/local/lib/python3.7/dist-packages/selenium/webdriver/common/virtual_authenticator.py', 'w') as file:

    file.writelines( data )

# Calls Selenium (It is important to edit the file before calling seleninum):

from selenium import webdriver

I know this is probably not the best solution, but it worked for me. I hope someone can come up with a better solution and explain why this is happening. Meanwhile, this will probably work for most people.

CodePudding user response:

Thank you: they fixed the issue

  • Related