问题
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