Search code examples
python-3.xselenium-chromedriver

'selenium.webdriver' has no attribute 'Chrome'


i was learing selenium and everyting was working just find, I made a new file called typing.py and it contained the following code:

from selenium import webdriver

url = "https://www.livechat.com/typing-speed-test/#/"

driver = webdriver.Chrome()

driver.get(url=url)

and then, out of blue, came this error all of a sudden:

    driver = webdriver.Chrome()
             ^^^^^^^^^^^^^^^^
AttributeError: partially initialized module 'selenium.webdriver' has no attribute 'Chrome' (most likely due to a circular import). Did you mean: 'chrome'?

I searched through internet, all solutions were indicating that selenium couldnt find the chrome driver app, and that I should provide with it; but that was not the case for me, since it was working just fine until a minute a go.

then I found this dude's comment Sanaa Ullah, upon following his instruction, at my surprise, it worked. But whyyy!! the directory was like this:

selenium
│   .env
│   amazon.py
│   cookie.py
│   linkedin.py
│   main.py
│   typing.py
│   test.py
│
└───__pycache__
        typing.cpython-312.pyc

And my question is, why??


Solution

  • The name of your python file typing.py is name-clashing with the typing.py module in wsproto package which is a dependency of selenium that gets installed with selenium (inspect pip freeze to see wsproto is a dependency and gets installed with selenium, thus its typing.py module gets added to the path). Hence, the AttributeError message detecting a circular import.

    As to "Why?" deleting your typing.py fixes the issue, it is no longer clashing with wsproto's typing.py module.