Java PhantomJS:page.onError-msg:TypeError:undefined不是函数
我正在构建一个工作流,用户可以在发送查询后获得结果。在这种情况下,用户将发送肽序列,然后显示结果。它在FireFox驱动程序中工作得非常好,但当我尝试使用PhantomJS测试headless浏览器时,它抛出了错误。 Selenium版本:2.53.1 PhantomJS版本:2.1.1 Java代码:Java PhantomJS:page.onError-msg:TypeError:undefined不是函数,java,selenium-webdriver,phantomjs,Java,Selenium Webdriver,Phantomjs,我正在构建一个工作流,用户可以在发送查询后获得结果。在这种情况下,用户将发送肽序列,然后显示结果。它在FireFox驱动程序中工作得非常好,但当我尝试使用PhantomJS测试headless浏览器时,它抛出了错误。 Selenium版本:2.53.1 PhantomJS版本:2.1.1 Java代码: package phantomjs; import java.io.IOException; import org.openqa.selenium.By; import org.openqa
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
我试图弄清楚为什么它会抛出错误,而不是显示结果,但还没有运气。有人知道如何解决这个问题吗?这是因为phantomjs的javascript引擎中没有polyfill(Function.prototype.bind)函数。现在有了(从2.1开始)。尝试下载。这是因为phantomjs的javascript引擎中没有polyfill(Function.prototype.bind)函数。现在有了(从2.1开始)。尝试下载。错误是由于您使用的PhantomJS版本没有
String.prototype.startsWith
。我似乎无法准确定位它在代码中发生的位置,是否有一行需要关注。也许您可以更改请求该dom元素的方式。@R.A.Lucas:由于“datasetbutton.click();”行出现错误。如果删除该行,则不会出现错误,但我需要“单击”以生成结果。那么,哪个Phantomjs与Selenium 2.53.1版本兼容?是否有其他方法可以找到该元素,因为我认为这就是问题所在?我不确定是否有更新版本的PhantomJS具有startsWith
ES6方法。错误是由于您使用的PhantomJS版本没有String.prototype.startsWith
。我似乎无法准确定位它在代码中发生的位置,是否有一行需要关注。也许您可以更改请求该dom元素的方式。@R.A.Lucas:由于“datasetbutton.click();”行出现错误。如果删除该行,则不会出现错误,但我需要“单击”以生成结果。那么,哪个Phantomjs与Selenium 2.53.1版本兼容?是否有其他方法可以找到该元素,因为我认为这就是问题所在?我不确定是否有更新版本的PhantomJS具有startsWith
ES6方法。