Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhantomJS with Selenium error: Message: 'phantomjs' executable needs to be in PATH

I am attempting to run this script:

https://github.com/Chillee/coursera-dl-all

However, the script fails at the line session = webdriver.PhantomJS() with the following error

Traceback (most recent call last):   File "dl_all.py", line 236, in <module>     session = webdriver.PhantomJS()   File "/home/<user>/.local/lib/python2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 51, in __init__     self.service.start()   File "/home/<user>/.local/lib/python2.7/site-packages/selenium/webdriver/common/service.py", line 69, in start     os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH.   Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.phantomjs.service.Service object at 0x7f6f632864d0>> ignored 

How do I add phantomjs to my PATH? I am running ubuntu 16.04 and installed selenium via npm install selenium.

like image 674
quantumbutterfly Avatar asked Jun 19 '16 02:06

quantumbutterfly


People also ask

Does Selenium support PhantomJS?

Selenium considers PhantomJS as deprecated, so you need to us either Chrome or Firefox in headless mode.

What is PhantomJS in selenium?

PhantomJS is a headless Webkit, which has a number of uses. In this example, we'll be using it, in conjunction with Selenium WebDriver, for conducting basic system tests directly from the command line. Since PhantomJS eliminates the need for a graphical browser, tests run much faster.


2 Answers

you need to download the DRIVER

after that session = webdriver.PhantomJS("c:\driverPath")

like image 61
Leon Barkan Avatar answered Sep 21 '22 11:09

Leon Barkan


Working Solution:

Assumming you are on windows - it is similar for linux

1) download phantomjs here: http://phantomjs.org/download.html pick windows/linux accordingly

2) unzip your phantomjs-2.1.1-windows.zip and save it to for example c drive such as C:\phantomjs-2.1.1-windows\bin (in here there is a phantomjs.exe that is the execute that your system needs)

3) On Windows10 edit your environment path to include this bin folder C:\phantomjs-2.1.1-windows\bin such as this example enter image description here

4) you may or may not restart your machine. Done! it should work! (Webdriver looks for phantomjs.exe and it should be ready now)

like image 23
Dung Avatar answered Sep 21 '22 11:09

Dung