AttributeError:“模块"对象没有属性"WebDriver" [英] AttributeError: 'module' object has no attribute 'webdriver'

查看:308
本文介绍了AttributeError:“模块"对象没有属性"WebDriver"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AttributeError :模块"对象没有属性"webdriver"

为什么在写入时发生此错误

import selenium 

并且在编写这样的代码时没有错误

from selenium import webdriver

解决方案

您会收到错误消息,因为webdriverselenium模块中的一个模块,如果没有显式import语句,您将无法访问这些模块.

如果您查看help(selenium),您会发现其中包含两个模块和一个非模块.

PACKAGE CONTENTS
    common (package)
    selenium
    webdriver (package)

它的行为符合我上面所述:

>>> 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
>>> 

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

解决方案

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
>>> 

这篇关于AttributeError:“模块"对象没有属性"WebDriver"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆