PhantomJS:page.onError - msg:TypeError:undefined不是函数

时间:2016-09-26 23:35:47

标签: java selenium-webdriver phantomjs

我正在构建一个工作流程,用户可以在发送查询后获得结果。在这种情况下,用户将发送肽序列,然后它将显示结果。它适用于FireFox驱动程序,但当我尝试使用PhantomJS测试无头浏览器时,它会抛出错误。 硒版:2.53.1 PhantomJS版本:2.1.1

Java代码:

package phantomjs;

import java.io.IOException;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.w3c.dom.DOMException;
public class ExtractData {
    public static void main(String[] args) throws InterruptedException, DOMException, IOException {
        String userpepseq="NLAVSQVVHK";
        WebDriver drivermassive = new PhantomJSDriver();
        drivermassive.get("http://exmaple.com/xyz_search.jsp");
        System.out.println(drivermassive.getTitle());
        WebElement searchdatapeptideseq=drivermassive.findElement(By.name("peptide"));
        System.out.println(searchdatapeptideseq.isDisplayed());
        searchdatapeptideseq.sendKeys(userpepseq);
        WebElement datasetbutton=drivermassive.findElement(By.xpath("//button[@class='proxi-selector' and contains (@onclick,'datasets')]"));
        datasetbutton.click();
        System.out.println(datasetbutton.isDisplayed());
        System.out.println(drivermassive.getCurrentUrl());
        Thread.sleep(5000);
        String sCellValuemassid = drivermassive.findElement(By.xpath(".//*[@class='result']/tbody")).getText();
        System.out.println(sCellValuemassid);
        drivermassive.quit();
    }
}

错误:

[ERROR - 2016-09-26T23:24:35.321Z] Session [61de22a0-8440-11e6-9376-7b90c4d612ac] - page.onError - msg: TypeError: undefined is not a function (evaluating 'query.startsWith("#")')

  phantomjs://platform/console++.js:263 in error
[ERROR - 2016-09-26T23:24:35.321Z] Session [61de22a0-8440-11e6-9376-7b90c4d612ac] - page.onError - stack:
  onUpdate (http://exmaple.com/xyz_search.jsp:166)
  updateData (http://exmaple.com/table_ss.js:411)
  render (http://exmaple.com/table_ss.js:340)
  selectTable (http://exmaple.com/xyz_search.jsp:285)
  onclick (http://exmaple.com/xyz_search.jsp:741)
  dispatchEvent (:0)
  U (:119)
  $ (:108)
  $ (:101)
  gh (:141)
  sh (:152)
  (anonymous function) (:152)
  (anonymous function) (:152)
  (anonymous function) (:153)

  phantomjs://platform/console++.js:263 in error

我想弄清楚为什么它会抛出错误而不是显示结果但是没有运气。任何人都知道如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

这是因为phantomjs在其javascript引擎中没有polyfill(Function.prototype.bind)函数。现在它(从2.1开始)。尝试下载latest phantomjs release