2016-04-21 23 views
28

Recentemente ho installato PhantomJS e incontrato questo errore nel mio primo run:.Impossibile caricare Atom '' find_element"

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) 

Questo codice funziona con Firefox WebDriver, ma non funziona con PhantomJS ricevo il seguente errore :

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' 
+0

Avete fatto che il file phantomjs.exe, o qualunque file sia, è nel tuo PATH Python? In tal caso, il processo phantomjs è attivo? – DuckPuncher

risposta

51

il motivo è che ho usato apt-get install Phantomjs per installarlo, ma sembra che si tratta di una versione non completa-funzionale Phantomjs installato da apt-get Quindi, scaricare manualmente dal sito Phantomjs e aggiungere la direzione contenente a. lo PATH variabile di ambiente.

+4

Lo stesso è successo qui: PhantomJS di Ubuntu 16.04 ha avuto questo errore, la versione del sito ha funzionato. – epx

+10

Sì, l'ho risolto facendo 'sudo apt purge phantomjs', poi lasciando installare nmn phantomjs con' npm install phantomjs-prebuilt'. – nnyby

+2

ho dovuto installare le dipendenze http://stackoverflow.com/a/36843608/977622 – psychok7

5

Per me è iniziare a lavorare dopo

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 
7

Questi sono i passi precisi che hanno lavorato per me:

  1. vecchi phantomjs Purge
    apt purge phantomjs

  2. Wget le ultime phantomjs (come da http://phantomjs.org/download.html)
    wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2

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

  4. spostato il phantomjs eseguibili in/usr/bin/(potrebbe essere necessario sudo)
    cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/

+0

Spostare il file binario in/usr/local/bin invece ... – Onlyjob