40

I have recently installed PhantomJS and encountered this error on my first run:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

driver = webdriver.PhantomJS()
driver.get("http://www.google.com")
driver.find_element_by_id('some_element').send_keys('something' + Keys.RETURN)

This code works with Firefox webdriver but does not work with PhantomJS. I get the following error:

Traceback (most recent call last):
  File "<PATHTOFILE>", line 20, in <module>
    driver.find_element_by_id('lst-ib').send_keys('something' + Keys.RETURN)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 266, in find_element_by_id
    return self.find_element(by=By.ID, value=id_)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 744, in find_element
    {'using': by, 'value': value})['value']
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 233, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 165, in check_response
    raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: Error - Unable to load Atom 'find_element' from file ':/ghostdriver/./third_party/webdriver-atoms/find_element.js'
Braiam
  • 1
  • 11
  • 47
  • 78
Clone
  • 3,378
  • 11
  • 25
  • 41
  • Did you make sure the phantomjs.exe file, or whichever file it is, is in your python PATH? If so, is the phantomjs process active? – RattleyCooper Apr 21 '16 at 15:22

3 Answers3

65

The reason is that I used apt-get install Phantomjs to install it, but it seems that it is a not full-functional Phantomjs version installed by apt-get. So, download manually from the Phantomjs website and add the containing direction to the PATH environment variable.

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
Zhongtian
  • 666
  • 6
  • 2
  • 4
    Same happened here: PhantomJS from Ubuntu 16.04 had this error, the version from site just worked. – epx May 02 '16 at 20:11
  • 14
    Yeah, I solved it by doing `sudo apt purge phantomjs`, then letting npm install phantomjs with `npm install phantomjs-prebuilt`. – nnyby Aug 04 '16 at 20:24
  • could you provide installation instructions for the downloaded version, please? Thanks! – webpaul Oct 07 '16 at 15:37
  • Note that the official PhantomJS site sadly doesn't support secure access through TLS. – aef Jun 06 '17 at 15:29
19

These are the precise steps that worked for me:

  1. Purge old phantomjs
    apt purge phantomjs

  2. Wget the latest phantomjs (as per http://phantomjs.org/download.html)
    wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2

  3. Untar it
    tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2

  4. Moved the phantomjs executable to /usr/bin/ (may need sudo)
    cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/

Community
  • 1
  • 1
Punit S
  • 3,079
  • 1
  • 21
  • 26
7

For me it start to work after

apt install nodejs-legacy # just an alias node/nodejs to make npm install work
apt purge phantomjs       # optionaly
npm install -g phantomjs  # most important part because apt installation failed for me
Nikita
  • 4,576
  • 1
  • 14
  • 11
  • It should be noted that the `-g` (`--global`) in the `npm` command line my _not_ be what you want! It practically soils your system, but having to use `sudo` (or getting an error) should provide a clue to anyone unaware, I'd hope ... – 0xC0000022L Dec 25 '20 at 23:28