无法加载Atom''find_element'

时间:2016-04-21 12:55:59

标签: python-3.x selenium phantomjs

我最近安装了PhantomJS并在第一次运行时遇到了这个错误:

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)

此代码适用于Firefox webdriver,但不适用于PhantomJS。我收到以下错误:

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'

3 个答案:

答案 0 :(得分:61)

原因是我使用apt-get install Phantomjs来安装它,但它似乎是由apt-get安装的不是全功能的Phantomjs版本。因此,从Phantomjs网站手动下载并将包含方向添加到PATH环境变量。

答案 1 :(得分:12)

这些是对我有用的精确步骤:

  1. 清除旧的幻影 apt purge phantomjs

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

  3. 解开它 tar xvjf phantomjs-2.1.1-linux-x86_64.tar.bz2

  4. 将phantomjs可执行文件移动到/ usr / bin /(可能需要sudo)
    cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/

答案 2 :(得分:6)

对我而言,它开始在

之后开始工作
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