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

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

问题描述

我正在尝试使用Selenium Webdriver生成Firefox实例。过去,在安装geckodriver并确保它位于我的PATH之后,我能够执行此操作。但是,我切换到使用phantomjs已有大约一年的时间,直到最近才决定再次试用Firefox。不幸的是,现在当我尝试实例化webdriver.Firefox对象时,我得到了AttributeError,称该对象没有称为 Firefox的此类属性。我不确定是什么导致了此错误。



下面是一个shell会话,用于显示我正在使用的环境和错误的性质:

 〜$其中python 
/ cygdrive / c / Python27 / python
〜$其中geckodriver
/ cygdrive / c / Windows / geckodriver
〜$ python -i
Python 2.7.12(v2.7.12:d33e0cf91556,Jun 27 2016,15:24:40)[MSC v.1500 64位(AMD64)在win32
上键入 help, copyright, credits或 license,以获取更多信息。
>>从硒导入webdriver
>> Firefox()
追溯(最近一次通话):
文件< stdin>,在< module>中的第1行。
AttributeError:模块对象没有属性 Firefox
>>> dir(webdriver)
['ActionChains','DesiredCapabilities','PhantomJS','Proxy','TouchActions,'__ builtins __','__ doc __','__ file __','__ name __','__ package__',' __path __','__ version __','common','phantomjs','remote']
>>> print(webdriver .__ file__)
C:\Python27\lib\site-packages\selenium\webdriver\__init __。pyc

注意:当我尝试从本地Windows cmd.exe和IDLE运行它时,会发生完全相同的事情,因此,此问题似乎并非特定于Cygwin p>

这在过去一直有效,我什至在我的python安装中甚至仔细检查了site-packages目录中的硒目录,以确认所有必需的文件都在那里。 firefox文件确实存在,所以我不知道为什么它们不被识别

解决方案

所以我仍然不是真的确定是我的硒安装中的更改导致了webdriver.Firefox停止运行,但是我能够通过使用以下方法更新硒来修复它:

  pip install -U硒

注意:如果您对硒库进行了任何自定义(例如在Windows上针对phantomjs的控制台窗口修复程序),您应该先备份自己的内容,然后再使用pip更新,然后还原修改后的文件或根据需要重新修改。


I am trying to use selenium webdriver to spawn an instance of Firefox. In the past, I was able to do this after installing geckodriver and making sure that it was in my PATH. However, I switched over to using phantomjs for about a year and only recently decided to give Firefox a spin again. Unfortunately, now when I try to instantiate the webdriver.Firefox object, I get an AttributeError saying the object as no such attribute called "Firefox". I am not sure what changed to cause this error.

Below is a shell session to show the environment I am working with and the nature of the error:

~$ which python
/cygdrive/c/Python27/python
~$ which geckodriver
/cygdrive/c/Windows/geckodriver
~$ python -i
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium import webdriver
>>> browser = webdriver.Firefox()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'Firefox'
>>> dir(webdriver)
['ActionChains', 'DesiredCapabilities', 'PhantomJS', 'Proxy', 'TouchActions', '__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', '__version__', 'common', 'phantomjs', 'remote']
>>> print(webdriver.__file__)
C:\Python27\lib\site-packages\selenium\webdriver\__init__.pyc

Note: The exact same thing happens when I try to run it from the native windows cmd.exe and from IDLE, so this issue does not appear to be specific to Cygwin

This worked in the past, and I even double checked the selenium dir in the site-packages dir in my python installation to confirm that all the necessary files are there. The firefox files are indeed there, so I have no idea why they're not being recognized

解决方案

So I am still not really sure what it is that changed in my selenium install that caused webdriver.Firefox to stop working, but I was able to fix it by updating selenium using

pip install -U selenium

Note: If you have any customizations to the selenium library (such as the console window fix for phantomjs on windows), you should back up your stuff first before updating with pip, then restore the modified files or re-modify as needed.

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

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