punkaceratop
punkaceratop

Reputation: 178

HtmlUnitDriver not getting page properly

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

Upvotes: 4

Views: 2814

Answers (2)

M_K
M_K

Reputation: 139

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

Upvotes: 0

jkieley
jkieley

Reputation: 71

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());

Upvotes: 2

Related Questions