Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to get Selenium to use phantomjs on a Windows machine. My code compiles without any error:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import cookielib
import re
from splinter import Browser

driver = webdriver.PhantomJS('C:/Program Files (x86)/phantomjs-1.9.2-windows')

But every single time I run it I get the error

Traceback (most recent call last):
  File "E:/~PROJECT/disinfo/py/bs.py", line 8, in <module>
    driver = webdriver.PhantomJS('C:/Program Files (x86)/phantomjs-1.9.2-windows')
  File "C:\Python27\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py", line 50, in __init__
    self.service.start()
  File "C:\Python27\lib\site-packages\selenium\webdriver\phantomjs\service.py", line 63, in start
    raise WebDriverException("Unable to start phantomjs with ghostdriver.", e)
selenium.common.exceptions.WebDriverException: Message: 'Unable to start phantomjs with ghostdriver.' ; Screenshot: available via screen 

I've been getting this error for hours. "Unable to start phantomjs with ghostdriver". The simplest examples online show installing selenium with PIP and then phantomjs with NodeJS NPM, which is how I did it. Selenium's location is in my PYTHONPATH as well. I frankly have no idea what the hell this thing wants from me. Any ideas?

share|improve this question
    
Same issues on basic code that once worked, thought I had broke my python structure at first. –  Shane Nov 12 '13 at 8:10
1  
Welp, it looks like phantomjs' dev has admitted that the python bindings are behind. github.com/detro/ghostdriver/issues/236 So much for using phantomjs. Wish I would've known that before I spent several ****ing hours trying to wrangle phantomjs to life. –  Amalgovinus Nov 16 '13 at 4:44
1  
Same feelings here. Why it is so important to learn code and not libraries unless they are maintained by a large community. You can never expect one guy to maintain his project especially if not making any money off of the hard work. –  Shane Nov 16 '13 at 20:47

2 Answers 2

up vote 9 down vote accepted

I ran into the same issue. I needed to provide the full path to the exe, as described in the documentation:

from selenium import webdriver

driver = webdriver.PhantomJS(executable_path='C:\phantomjs-1.9.2\phantomjs.exe')

share|improve this answer
    
This did indeed allow it to dial out, hooray. Now the only problem is, every element I try to print, it just gives me a "selenium.webdriver.phantomjs.webdriver.WebDriver object at 0x0000000002F54668" or a unicode ID. I recommend lorien's Grab instead. bitbucket.org/lorien/grab/src/… –  Amalgovinus Dec 7 '13 at 23:20
    
true story!! wish I could upvote 5 times. –  HelloW Dec 20 '13 at 13:40
    
Didn't work for me... I had to edit service.py as per DT_Lvhyy's answer. –  Deep-B Feb 17 at 20:47
    
It looks like for Ubuntu and Linux systems, ~ should be the actual path from root to the directory –  Delos Chang Mar 18 at 6:47

You need to modify ...\Python27\Lib\site-packages\selenium-2.39.0-py2.7.egg\selenium\webdriver\phantomjs\service.py

This google code page would help.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.