AttributeError:模块'selenium.webdriver'没有属性'Firefox'

时间:2016-11-11 19:22:10

标签: python python-3.x selenium selenium-webdriver attributeerror

在这里完成新秀;只是尝试在程序中使用这段代码打开Firefox会导致在主题中指定的AttributeError:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe')
browser = webdriver.Firefox(firefox_binary=binary)

奇怪的是,直接在Python shell中逐行输入代码可以正常工作。我该如何解决?

以下是IDLE中的代码行:

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> from selenium import webdriver
>>> from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
>>> binary = FirefoxBinary('C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe')
>>> browser = webdriver.Firefox(firefox_binary=binary)
>>> 

运行它会按预期打开浏览器。

这是追溯:

Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 
============== RESTART: C:\Users\Paweł\MyPythonScripts\email.py ==============
Traceback (most recent call last):
  File "C:\Users\Paweł\MyPythonScripts\email.py", line 4, in <module>
    from selenium import webdriver
  File "C:\Users\Paweł\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\__init__.py", line 18, in <module>
    from .firefox.webdriver import WebDriver as Firefox  # noqa
  File "C:\Users\Paweł\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 19, in <module>
    import http.client as http_client
  File "C:\Users\Paweł\AppData\Local\Programs\Python\Python35-32\lib\http\client.py", line 71, in <module>
    import email.parser
  File "C:\Users\Paweł\MyPythonScripts\email.py", line 8, in <module>
    browser = webdriver.Firefox(firefox_binary=binary)
AttributeError: module 'selenium.webdriver' has no attribute 'Firefox'
>>>

0 个答案:

没有答案