'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 1:[1]

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.

Solution 2:[2]

i am working on ubuntu 16.04 and i solve this problem by using geckodriver.exe file.

:: at first you have to install selenium using this command >>

        for python2:-  python -m pip install --user selenium
        for python3:-  python3 -m pip install --user selenium

:: next step download geckodriver using link given below >>

       https://github.com/mozilla/geckodriver/releases

:: since i am using ubuntu so i download geckodriver-v0.24.0-linux64.tar.gz
now extract it.

:: now in the python code add these lines >>

 from selenium import webdriver

 browser = webdriver.Firefox(executable_path = '/home/aman/Downloads/geckodriver')
 browser.get('https://www.google.com')
 browser.close()

:: in my pc i extract geckodriver in /home/aman/Downloads/geckodriver so you have to put whole path for geckodriver file where you extract your file.

:: now run this python file, i hope this will definitely work for you.

Solution 3:[3]

For me, it was a typo. The correct way is "Firefox", not "FireFox" (notice the second capital "F")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ag415
Solution 2
Solution 3 Mike Johnson Jr