HtmlUnitDriver not getting page correctly

I'm new to this, basically I'm trying to use HtmlUnitDriver, this is my code:

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

But the source of the page I received is:

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

I tried to create a new HtmlUnitDriver (true), but it still does not load Google. I already add the selenium server separately to the class path. Am I doing something wrong? Thanks you

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

+4
source share
2 answers

HtmlUnitDriver by default disables javaScript google.com is highly dependent 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
source

The problem, of course, is due to the lack of a proxy server when htmlunitdriver starts. You will need to provide proxy information.

0
source

All Articles