Search code examples
pythonseleniumfirefoxwebdrivercygwin

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


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


Solution

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