Java Selenium HtmlUnitDriver-由于Ajax调用,Gwt源代码未填充
我使用JavaSeleniumHtmlUnitDriver来验证Gwt源代码的html是否由于Ajax调用而未填充。有没有办法执行实际页面并获取页面的源代码?我尝试启用Js,但仍然没有成功。如果您需要处理动态内容,那么最好的机会可能是使用带有JavaScript引擎的浏览器/驱动程序。以下是无头PhantomJS驱动程序的示例:Java Selenium HtmlUnitDriver-由于Ajax调用,Gwt源代码未填充,java,selenium,junit,Java,Selenium,Junit,我使用JavaSeleniumHtmlUnitDriver来验证Gwt源代码的html是否由于Ajax调用而未填充。有没有办法执行实际页面并获取页面的源代码?我尝试启用Js,但仍然没有成功。如果您需要处理动态内容,那么最好的机会可能是使用带有JavaScript引擎的浏览器/驱动程序。以下是无头PhantomJS驱动程序的示例: System.setProperty("phantomjs.binary.path", "..."); WebDriver driver = new PhantomJ
System.setProperty("phantomjs.binary.path", "...");
WebDriver driver = new PhantomJSDriver();
WebDriverWait wait = new WebDriverWait(driver, 20);
// load the page
driver.get("http://...");
// wait for a dynamic element to be created
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("...")));
// get the page source
String source = driver.getPageSource();
如果您需要处理动态内容,那么最好的方法可能是使用带有JavaScript引擎的浏览器/驱动程序。以下是无头PhantomJS驱动程序的示例:
System.setProperty("phantomjs.binary.path", "...");
WebDriver driver = new PhantomJSDriver();
WebDriverWait wait = new WebDriverWait(driver, 20);
// load the page
driver.get("http://...");
// wait for a dynamic element to be created
wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("...")));
// get the page source
String source = driver.getPageSource();