Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 989
fady malak Avatar asked Jun 14 '16 02:06

fady malak


1 Answers

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
>>> 
like image 144
Anonymous Avatar answered Oct 14 '22 04:10

Anonymous