Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium/PhantomJS raises error

I'm trying to run PhantomJS driver in Python but I'm getting error. I've read that I should pass the whole path as an argument but it didn't help.

Here is the code:

from selenium import webdriver

# driver = webdriver.Chrome('D:\Python_projects\chromedriver_win32/chromedriver.exe') # this works
driver = webdriver.PhantomJS(executable_path='D:\Python\phantomjs-2.0.0-windows\bin\phantomjs.exe')

ERROR:

Traceback (most recent call last):
  File "path to script", line 8, in <module>
    driver = webdriver.PhantomJS(executable_path='D:\Python\phantomjs-2.0.0-windows\bin\phantomjs.exe')
  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 75, 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

Do you know what am I doing wrong?

like image 224
Milano Avatar asked Apr 25 '15 19:04

Milano


2 Answers

Make the path in raw string, add 'r': 

driver = webdriver.PhantomJS(executable_path=r'D:\Python\phantomjs-2.0.0-windows\bin\phantomjs.exe')
like image 94
WEI YU Avatar answered Nov 15 '22 18:11

WEI YU


For simplicity's sake place the executable in the same directory as your script:

driver = webdriver.PhantomJS() # now there's no need for a path
like image 39
Malik Brahimi Avatar answered Nov 15 '22 19:11

Malik Brahimi