Python – Selenium Python Headless Webdriver (PhantomJS) Not Working

linuxphantomjspythonseleniumsplinter

So I'm having trouble getting selenium to work with a headless driver, specifically PhantomJS. I'm trying to get it to work on an Ubuntu webserver (Ubuntu 14.04.2 LTS).

Running the following commands from a python interpreter (Python 2.7.6) gives:

from selenium import webdriver
driver = webdriver.PhantomJS()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/service.py", line 76, in start
    raise WebDriverException("Unable to start phantomjs with ghostdriver: %s" % e)
selenium.common.exceptions.WebDriverException: Message: Unable to start phantomjs with ghostdriver: [Errno 2] No such file or directory

I've also tried:

driver = webdriver.PhantomJS(executable_path="/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__
    self.service.start()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/service.py", line 76, in start
    raise WebDriverException("Unable to start phantomjs with ghostdriver: %s" % e)
selenium.common.exceptions.WebDriverException: Message: Unable to start phantomjs with ghostdriver: [Errno 13] Permission denied

I also added it to the python path:

import sys
sys.path.append("/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/")

I am currently logged in as root. Permissions for the phantomjs directory are:

drwxr-sr-x  2 root staff 4096 Sep  9 06:58 phantomjs

and for phantomjs/webdriver.py:

-rw-r--r--  1 root root  2985 Sep  9 06:58 webdriver.py

I've confirmed selenium is installed and up-to-date (pip install selenium –upgrade). It is installed at:

/usr/local/lib/python2.7/dist-packages/selenium/webdriver/phantomjs/

print selenium.__version__
2.47.1

I've looked at:

I've been testing my program on a locally hosted server (on OSX), using chromedriver. I'm actually using Splinter (https://splinter.readthedocs.org/en/latest/#headless-drivers) for that, and have tried the other headless drivers (django and zope.testbrowser) but have had similar issues.

I'm open to any suggestions, I don't mind changing driver if required.

Thanks in advance for any help.

Best Answer

I had the same problem as you with the same errors. I have tried to install it on openSuse Server. I ended up installing PhantomJS form source -unfortunately without any success. The way that worked for me was installing Phantomjs via npm

sudo npm install -g phantomjs
Related Topic