HtmlUnitDriver not getting page properly

依然范特西╮ 提交于 2019-12-10 17:00:03

问题


I'm a newbie at this, basically I'm trying to use the HtmlUnitDriver, this is my code:

WebDriver driver = new HtmlUnitDriver();
driver.get("http://www.google.com");
System.out.println(driver.getPageSource());

But the page source I got is:

<?xml version="1.0" encoding="UTF-8"?>
<html>
  <head/>
  <body/>
</html>

I have tried to to new HtmlUnitDriver(true) but it's still not loading google I have already add the selenium server stand alone to the class path. Am I doing anything wrong? Thank you

P.S: Im using selenium-server-standalone-2.24.1.jar and jre 1.7


回答1:


HtmlUnitDriver defaults to having javaScript disabled google.com relies heavily on javascript. try using driver.setJavascriptEnabled(true)

WebDriver driver = new HtmlUnitDriver();
driver.setJavascriptEnabled(true)
driver.get("http://www.google.com");
System.out.println(driver.getPageSource());



回答2:


The issue is definitely due to proxy missing while starting htmlunitdriver. You will have to provide proxy details



来源:https://stackoverflow.com/questions/11248300/htmlunitdriver-not-getting-page-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!