phantomjs无法在页面上找到元素

时间:2016-08-23 00:29:40

标签: r phantomjs rselenium

最近,我在RSelenium下驾驶phantomj时遇到了麻烦。浏览器似乎无法使用@everywhere include()在页面上找到任何内容。如果我传递的内容很简单:

findElement()

我收到以下错误:

library("RSelenium")
RSelenium::checkForServer()
RSelenium::startServer()
rd <- remoteDriver(browserName = "phantomjs")
rd$open()
Sys.sleep(5)

rd$navigate("https://www.Facebook.com")
searchBar <- rd$findElement(using = "id", "email")

有关导致此问题的任何想法?我导航到哪个页面似乎并不重要;它只是在我尝试在网页上找到一个元素时失败。这个问题最近开始了,当我的cron作业开始失败时我注意到了这个问题。

我正在使用R 3.3.1和phantomjs 2.1.1在Ubuntu 14.04 LTS中工作。我不怀疑某种类型的兼容性问题,因为它最近才起作用,我没有更新任何内容。

1 个答案:

答案 0 :(得分:2)

您安装的phantomjs版本可能有限。见here

  
      
  • 由于预先构建的无源Selenium blob而禁用了Ghostdriver。
  •   
  • 添加了README.Debian解释与上游“phantomjs”的差异。
  •   

如果您最近使用apt-get进行了安装,那么很可能就是这种情况。您可以从phantomjs website下载并将bin位置放在PATH中。

或者使用npm为您安装版本

npm install phantomjs-prebuilt

这将是node_modules/.bin/phantomjs

中bin的链接

由于apt-get限制背后的原因,您可以阅读包含here的README.Debian文件。

  

限制

     

与静态链接的原始“phantomjs”二进制文件不同   修改了QT + WebKit,Debian包是用系统libqt5webkit5构建的。   不幸的是后者没有webSecurity扩展   “--web-security = no”预计会失败。

     

https://github.com/ariya/phantomjs/issues/13727#issuecomment-155609276

           

由于删除了无源预建blob,Ghostdriver被削弱了:

     

的src / ghostdriver / THIRD_PARTY / webdriver的原子/ *

     

因此,所有PDF功能都已损坏。

           

PhantomJS无法在无头模式下运行(如果没有X服务器)   可用)。

     

不幸的是,它无法在Debian中修复。实现无头   上游与定制的QT + Webkit静态链接。我们不想   那些项目的船叉。最终说服会很棒   上游使用标准库。同时可以使用“xvfb-run”   来自“xvfb”包:

xvfb-run --server-args="-screen 0 640x480x16" phantomjs

如果您不想为phantomjs设置路径,那么您可以将其添加为额外的:

library(RSelenium)

selServ <- startServer()
pBin <- list(phantomjs.binary.path = "/home/john/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs")
rd <- remoteDriver(browserName = "phantomjs"
                   , extraCapabilities = pBin)
Sys.sleep(5)
rd$open()

rd$navigate("https://www.Facebook.com")
searchBar <- rd$findElement(using = "id", "email")

rd$close()
selServ$stop()
相关问题