Search code examples
pythonselenium-webdriverchromium

AttributeError: module 'selenium.webdriver' has no attribute 'webdriver'


I've installed Selenium correctly as well as the Chromium webdriver for Selenium, and I keep getting the following error:

    Traceback (most recent call last):
  File "C:/Users/Turtle/PycharmProjects/SpotifyWebscraper/seleniumTest.py", line 3, in <module>
    driver = webdriver.chrome()
TypeError: 'module' object is not callable

Here is my code:

from selenium import webdriver

driver = webdriver.chrome()
driver.get("htts://www.google.com")

print(driver.title)
print(driver.current_url)

driver.quit

I've checked in the folders correctly and the files seem to be in the right positions:

C:\Users\Turtle\AppData\Local\Programs\Python\Python38\Lib\site-packages\selenium-4.0.0a3-py3.8.egg\selenium\webdriver\chromium

contains file webdriver.py.


Solution

  • If you look at the way Selenium imports the various flavours of webdriver to selenium.webdriver you can see that the import you want is Chrome

    from .firefox.webdriver import WebDriver as Firefox  # noqa
    from .chrome.webdriver import WebDriver as Chrome  # noqa
    

    So you would do driver = webdriver.Chrome() or if you want Firefox, webdriver.Firefox()

    By doing webdriver.chrome() you're importing & calling the actual chrome module

    In terms of your new error, you need to download the chromedriver executable and make sure it's in a folder which is available to python (included in your PATH). You can download chromedriver here; https://sites.google.com/a/chromium.org/chromedriver/downloads