AttributeError Issue: module 'selenium.webdriver' has no attribute 'Chrome'
Asked Answered
S

12

7

there is no chrome module present under webdriverI have just started Selenium using Python. And I'm facing the Attribute error issue.

  • Have Installed Python 3.6.5 and installed the latest selenium packages(selenium-3.11.0)

  • Have also added Scripts and Python folder path in the Environment variable:PATH.

  • Downloaded the chromedriver.exe and have added the respective file path into the environment variable.

But while running the below code:

from selenium import webdriver
driver = webdriver.Chrome("E:\Selenium\chromedriver_win32\chromedriver.exe")

It's throwing the following error:

C:\Users\Sooraj\venv\firstpgm\Scripts\python.exe C:/Users/Sooraj/PycharmProjects/Selenium/First.py
Traceback (most recent call last):
  File "C:/Users/Sooraj/PycharmProjects/Selenium/First.py", line 2, in 
<module>
driver=webdriver.Chrome("E:\Selenium\chromedriver_win32\chromedriver.exe")
AttributeError: module 'selenium.webdriver' has no attribute 'Chrome'

Process finished with exit code 1

Tried all the other solutions provided here in Stack Overflow like uninstalling and reinstalling Python and upgrading the selenium.But was of no help.

The code was run using PyCharm IDE but when run using IDLE it's working fine.

Could find the folders like firefox,chrome,safari,phantomjs,android etc..under Sitepackages -> selenium -> webdriver.But not sure why it is still showing "Webdriver has no attribute chrome"

The above screenshot attached. Shows no module chrome() under webdriver

Any help would be appreciated.

Shepp answered 1/5, 2018 at 8:6 Comment(1)
Possible duplicate of Python : no module named seleniumMarquis
T
7
from selenium import webdriver

driver = webdriver.Chrome()

This is the correct way how to write that code, also if u want to use firefox or something else then change chrome to firefox ... also read 1st a documentation and look for some examples, then put it here if u find nothing

Also use pip install selenium !

Takamatsu answered 1/5, 2018 at 17:0 Comment(0)
F
2

You can delete the file you recently created. I am facing same issue when i come to this thread and nothing worked for me. I just deleted my recent file and everything works fine :-)

Before creating new python file selenium work fine. it start showing this error when i create new python file in same folder. When i delete the file , everything work fine as before.

Foreknow answered 1/9, 2019 at 7:39 Comment(1)
This just happened to me. Why does adding a .py file in the same directory break selenium?Rhettrhetta
B
1

you should write it like this : browser = webdriver.Chrome(executable_path=r"chromedriver.exe") and please make sure that you have Google Chrome installed on your system.

Bianca answered 1/5, 2018 at 8:47 Comment(1)
I tried your input. chromedriver.exe is already downloaded. and i have added the path in the environment variable . But still it did not workShepp
T
1

Try using following command instead

driver = webdriver.chrome.webdriver.WebDriver(executable_path='E:\Selenium\chromedriver_win32\chromedriver.exe')

Reference: Official document https://seleniumhq.github.io/selenium/docs/api/py/webdriver_chrome/selenium.webdriver.chrome.webdriver.html#selenium.webdriver.chrome.webdriver.WebDriver

Tani answered 1/5, 2018 at 9:11 Comment(1)
I tried your input . But still the error persist.... Should I degrade my python version?Shepp
B
1

first check google chrome version of your system by using this in URL chrome://version/

then download chrome driver from below mention website according to chrome version https://chromedriver.chromium.org/downloads

then type this in pycharm or sublime text

import selenium

from selenium import webdriver

driver = webdriver.chrome.webdriver.WebDriver(executable_path='C:/drivers/chromedriver_win32 (1)/chromedriver.exe')

driver.get("http://www.python.org")

and RUN, surely it works

Bosun answered 19/5, 2020 at 10:29 Comment(0)
T
0

Windows 7: Pycharm IDE version 2018.1.2 Navigate to

Project Name->venv

Open pyenv.cfg

Change

include-system-site-packages = false

to

include-system-site-packages = true
Thought answered 26/7, 2018 at 15:27 Comment(0)
U
0

please check your filename, it is not be special name. for example selectors.py

Unawares answered 20/6, 2020 at 20:37 Comment(1)
Welcome to Stack Overflow. Note that the question is two years old. As you gain reputation you'll be able to leave comments, but please do not use the answer feature to leave comments.Pangermanism
E
0

use this and then hit invoke

from selenium import webdriver driver = webdriver.Chrome(executable_path=yourpath\chromedriver.exe")

Elodea answered 7/3, 2022 at 10:39 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewCaudill
S
0

Well what you can do is to consider this official page selenium

Three Ways to Use Drivers...

The first way works well. For this you have to install webdrivermanager

pip install webdriver-manager

and then

# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))

github link for more

Stormi answered 23/3, 2022 at 8:40 Comment(0)
M
0

The issue seems with Pycharm.

Go to Python Packages which would be displayed at the bottom linePycharm Image

There search for selenium and install from there if not installed. Once installation is done rerun the script

If issue persist try to add chromedriver.exe file in C:\Python310\Scripts folder and check once

Molina answered 19/6, 2022 at 14:25 Comment(0)
A
0
from selenium import webdriver

driver = webdriver.chrome.webdriver.WebDriver(executable_path='/Users/yatin/Downloads/chromedriver')

driver.get("http://www.python.org")
  • this worked perfectly fine in pycharm. Note: you must have already installed the selenium package from the interpreter

and also match the current chrome version and chrome driver you are downloading, should be same version.

though this command will work but this is depricated so here is new one:

from selenium import webdriver

from selenium.webdriver.chrome.service import Service

service_obj = Service("/Users/yatin/Downloads/chromedriver")

driver = webdriver.chrome(service=service_obj)

driver.get("www.netflix.com")
Alike answered 18/11, 2022 at 18:15 Comment(1)
Please use the code highlighting when using code in your answer. It improves readabilityHibbler
E
-1

I had the same problem and we solved it!! I installed the newest version of python which is 3.9. I ran it and it yelled at me for selenium. So I went into command prompt and did :

pip install selenium

It installed selenium. I ran it, and it worked.

Eshelman answered 29/7, 2021 at 17:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.