Questions tagged [htmlunit]

HtmlUnit is a "headless browser". Which means that there is no browser GUI and it does no rendering. Though it has a CSS and JS engine to simulate a real browser. Primary purpose is testing and information extraction.

HtmlUnit is a "GUI-Less browser for Java programs". It models HTML documents and provides an API that allows you to invoke pages, fill out forms, click links, etc... just like you do in your "normal" browser.

It has fairly good JavaScript support (which is constantly improving) and is able to work even with quite complex AJAX libraries, simulating Chrome, Firefox or Internet Explorer depending on the configuration used.

It is typically used for testing purposes or to retrieve information from web sites.

HtmlUnit is not a generic unit testing framework. It is specifically a way to simulate a browser for testing purposes and is intended to be used within another testing framework such as JUnit or TestNG.

HtmlUnit is used as the underlying "browser" by different Open Source tools like Canoo WebTest, JWebUnit, Selenium WebDriver, JSFUnit, Celerity, ...

HtmlUnit was originally written by Mike Bowler of Gargoyle Software and is released under the Apache 2 license.

Useful links

1835 questions
5
votes
1 answer

Is it possible to use HTTPS proxy in HTMLunit?

I am new in HTMLunit and trying to set HTTPS proxy for HTMLunit. I tried to use https:// just before the HOST IP, but I got Exception. Anyone can help me to solve this issue? Update: My Code is: WebClient webClient = new …
5
votes
1 answer

HTMLUnit and handling cookies ("WARNING: Cookie rejected")

I'm looking for a way to accept cookies (all cookies) using HTMLUnit I'm trying to login to my wordpress site using HTMLUnit but I can't submit the form (and therefor can not login) when the cookies are rejected as my error is: Jul 14, 2012…
user1372760
  • 89
  • 1
  • 5
5
votes
3 answers

HtmlUnit slower than GUI browser?

Why HtmlUnit is so much slower than GUI browsers? For instance, HtmlUnit loads this page http://oltexpress.airkiosk.com/cgi-bin/airkiosk/I7/181002i?O2=2 in 14sec (when CSS support is turned off) while FF does it in 5sec (after clearing cache, with…
biera
  • 2,608
  • 1
  • 24
  • 26
5
votes
1 answer

WebDriver HTMLUnit issues with Ajax

I want to test a site using selenium webdriver (java), but that site contains ajax and HTMLUnit does not see the ajax content. Is there a workaround? Example: WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_3_6); //login into your…
Krzys
  • 81
  • 1
  • 5
5
votes
7 answers

How to tell htmlunit to ignore certain errors

I am currently trying out HtmlUnit. I want to fill out an form and then submit it. But this results in an error, which seems to be caused by a file not being accessible, which results in a connection reset being thrown. How can I suppress this, as…
Sim
  • 4,199
  • 4
  • 39
  • 77
4
votes
2 answers

How to limit HttpClient response length

I'm using htmlunit with httpclient. How can I limit the response body length of httpclient to say 1MB?
John
  • 1,699
  • 5
  • 20
  • 29
4
votes
1 answer

HtmlUnit can't retrieve page after downloading a file

I'm having this weird problem with HtmlUnit in Java. I am using it to download some data from a website, the process is something like this: 1 - Login 2 - For each element (cars) ----- 3 Search for car ----- 4 Download zip file from a link The…
oli206
  • 433
  • 7
  • 17
4
votes
1 answer

filtering externally loaded javascript in htmlunit

While using htmlunit to scrape a webpage, I occasionally notice warnings like these that flood the console output. Jul 24, 2011 5:12:59 PM com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter warning WARNING: warning: message=[Calling…
DannyTree
  • 1,137
  • 2
  • 12
  • 16
4
votes
1 answer

Opening an SSL web-browser connection in HtmlUnit library

I've searched through web for couple hours on this issue, and none of the answers I found didn't really fit into my problem, so here's me, asking my first-ever question in SOF. So, I'm trying to open a web-browser from a java program using the…
Don Spike
  • 41
  • 1
  • 3
4
votes
1 answer

How to debug Htmlunit traffic with Fiddler using PAC (proxy auto-config)

I have an application using Htmlunit and need put Fiddler to intercept traffic, i read something about configure it via PAC (proxy auto-config) javascript file that comes with but i cant found the article again. How to configure Htmlunit via PAC ?…
nedprx
  • 41
  • 3
4
votes
2 answers

How to get final redirect of a URL with HtmlUnit

I have the URL https://www.facebook.com/ads/library/?id=286238429359299 which gets redirected to…
orange
  • 5,297
  • 12
  • 50
  • 71
4
votes
1 answer

How to make HtmlUnit's WebClient accelerate execution of javascript to be triggered by window.setTimeout?

I am using the Java library HtmlUnit to create a regression test suite for a web app. I have an "onload" handler hooked in the body of pages of the app to redirect to a timeout page after the session would have expired. The handler is some…
Roboprog
  • 3,054
  • 2
  • 28
  • 27
4
votes
2 answers

Why doesn't HTMLunit work on this https webpage?

I'm trying to learn more about HTMLunit and doing some tests at the moment. I am trying to get basic information such as page title and text from this site: https://....com (removed the full url, important part is that it is https) The code I use is…
Tunca Ersoy
  • 339
  • 1
  • 4
  • 18
4
votes
2 answers

Given an HtmlUnit HtmlPage object, how do I get the URI of its Document?

The page object I have is the result of a long chain of click() calls (just in case you were wondering how I could have a page object without knowing the URL used to obtain it). The method HtmlPage.getDocumentURI is not implemented.…
pdc
  • 2,314
  • 20
  • 28
4
votes
1 answer

How to measure the number of JavaScript functions that define new Strings

I was looking through this paper, in which they use HTMLUnit to "measure the number of invocations of JavaScript functions that can be used to define new strings (such as substring, and fromCharCode), and the number of string uses (such as write…
Rehaan Ahmad
  • 794
  • 8
  • 23