7

AttributeError: 'module' object has no attribute 'webdriver'

why this error happen when write

import selenium 

and when write code like this no error happen

from selenium import webdriver
5
  • import selenium works fine in my case. Can you show the full error message? Commented Jun 14, 2016 at 2:20
  • it was work for me until i install komodo and get error Commented Jun 14, 2016 at 2:47
  • Traceback (most recent call last): File "C:\Users\fady\Desktop\sad.py", line 2, in <module> a = selenium.webdriver.Firefox() AttributeError: 'module' object has no attribute 'webdriver' Commented Jun 14, 2016 at 2:47
  • Quick check. Have you by any chance created a file called selenium.py? Commented Jun 14, 2016 at 3:01
  • 2
    no and file name is sad.py Commented Jun 14, 2016 at 3:41

1 Answer 1

9

You get an error because webdriver is a module inside the selenium module, and you can't access modules without an explicit import statement.

If you take a look at help(selenium), you'll see there are two modules and one non-module contained inside.

PACKAGE CONTENTS
    common (package)
    selenium
    webdriver (package)

And it behaves according to what I described above:

>>> selenium.common # doesn't work
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'common'
>>> from selenium import common # works
>>> selenium.selenium # works
<class 'selenium.selenium.selenium'>
>>> selenium.webdriver # doesn't work
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'webdriver'
>>> from selenium import webdriver # works
>>> 
Sign up to request clarification or add additional context in comments.

1 Comment

but code was working before install komodo ide i try to reinstall python but the error still happen

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.