4

I am getting this error message when I try to use a python script to open a firefox browser on Ubuntu Linux 14.04:

File "seleniumtest.py", line 3, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 145, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error

The sample code is:

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://www.google.com')

Dependencies like geckodriver have been installed.

wget https://github.com/mozilla/geckodriver/releases/download/v0.13.0/geckodriver-v0.13.0-linux64.tar.gz
tar -xvzf geckodriver-v0.13.0-linux64.tar.gz
rm geckodriver-v0.13.0-linux64.tar.gz
chmod +x geckodriver
cp geckodriver /usr/local/bin/

With the addition of "executable_path="/usr/local/bin/geckodriver", the output is as follows:

File "seleniumtest.py", line 3, in <module>
browser = webdriver.Firefox(executable_path="/usr/local/bin/geckodriver")
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 145, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
ykw
  • 91
  • 3
  • 9
  • 1
    Possible duplicates: http://stackoverflow.com/questions/38833589/oserror-errno-8-exec-format-error-selenium and http://stackoverflow.com/questions/36141032/python-selenium-chromedriver-oserror-errno-8-exec-format-error Different OS, but same error and probably the same solution, i.e., make sure you only have one instance of geckodriver anywhere in your path – Mark Lapierre Mar 11 '17 at 21:39
  • 1
    @Mark Lapierre Yup! I only have one instance of geckodriver. I typed "which geckodriver" in terminal and copied and pasted the link to executable_path="/path/to/geckodriver" I don't think I have multiple instances of firefox drivers though. I'm assuming that the default pre-installed firefox has its own driver and the selenium package has its own set of browser drivers. – ykw Mar 11 '17 at 23:29
  • 1
    Does `which -a geckodriver` show only one? One of the other issues had a problem with multiple drivers even after specifying one. – Mark Lapierre Mar 12 '17 at 01:24
  • 1
    @MarkLapierre Yes. It shows only one. – ykw Mar 12 '17 at 14:30
  • 1
    Hmm. The only other problem I'm aware of would be if your OS was not 64-bit, like the driver. Is it? – Mark Lapierre Mar 12 '17 at 22:08
  • 1
    @MarkLapierre My OS is 64 bit. – ykw Mar 14 '17 at 08:52

3 Answers3

0

You should provide the location of your installed geckodriver:

browser = webdriver.Firefox(executable_path="/path/to/geckodriver")
Baryo
  • 314
  • 1
  • 9
  • I am still getting the same error. I entered "which geckodriver" in terminal and copied and pasted that link to replace "/path/to/geckodriver" – ykw Mar 11 '17 at 23:19
0

There is one alternative to using Firefox. We can use Chromium instead. These are the setup steps:

sudo apt-get --yes --force-yes install chromium-browser xvfb unzip

wget -N http://chromedriver.storage.googleapis.com/2.26/chromedriver_linux32.zip
unzip chromedriver_linux32.zip
chmod +x chromedriver

sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
ykw
  • 91
  • 3
  • 9
  • How is this solving the problem ? He needs to run Firefox , if he was ok with other browsers , there are lot of options available. – user3251882 Mar 14 '17 at 11:18
  • @user3251882 Maybe it's an open bug with firefox and Selenium so if there's anyone also having problems with automating web browsing with the pre-installed firefox in linux then this is another alternative. Still can't solve the firefox problem though. Could be a problem with the drivers at the lower levels... – ykw Mar 15 '17 at 17:06
0

If you are using Mac OS make sure you have run this command in Terminal

chmod a+x geckodriver
Ahmed Awan
  • 347
  • 3
  • 9