peacecoder peacecoder - 11 months ago 97
Python Question

Error on Firefox Driver using Selenium/Python

I'm getting an error when trying to execute a simple python script using Selenium. Here are the script and the error along with my environment information (I'm using a virtual environment). (I get a different error when I try to use the Chrome driver). Any help would be greatly appreciated.

// SCRIPT //

import mechanize
import urllib2 #requests web pages
from selenium import webdriver
from selenium.common.exceptions import NoSuchAttributeException
from selenium.webdriver.common.keys import Keys #allows us to press keys

import os
import re #regular expressions module

br = mechanize.Browser()
br.addheaders = [('User-agent','Firefox')]

browser = webdriver.Firefox()


Traceback (most recent call last):
File "", line 18, in <module>
browser = webdriver.Firefox()
File "/Users/rachael/workspace/rbexplorations/email_scraping_challenge/venv/lib/python2.7/site-packages/selenium/webdriver/firefox/", line 77, in __init__
self.binary, timeout),
File "/Users/rachael/workspace/rbexplorations/email_scraping_challenge/venv/lib/python2.7/site-packages/selenium/webdriver/firefox/", line 49, in __init__
File "/Users/rachael/workspace/rbexplorations/email_scraping_challenge/venv/lib/python2.7/site-packages/selenium/webdriver/firefox/", line 67, in launch_browser
File "/Users/rachael/workspace/rbexplorations/email_scraping_challenge/venv/lib/python2.7/site-packages/selenium/webdriver/firefox/", line 90, in _start_from_profile_path
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 710, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory


python 2.7.10
mechanize (0.2.5)
pip (7.1.2)
selenium (2.48.0)
setuptools (18.2)
wheel (0.24.0)
OSX 10.11.2

Answer Source

This error happens when Selenium didn't find Firefox installation directory / firefox executable in its default location. Uninstall and Reinstall firefox with its default settings and run the script again.

Some of the links discussing about this issue:

Selenium: FirefoxProfile fails with not found exception

How to deal with OSErrors with selenium?