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
12
votes
1 answer

Does HtmlUnit load images when it browses page?

as above. Does it load images?
oneat
  • 10,778
  • 16
  • 52
  • 70
12
votes
4 answers

How can I tell HtmlUnit's WebClient to download images and css?

How can I make WebClient download external css stylesheets and image bodies just like a usual web browser does?
Fluffy
  • 27,504
  • 41
  • 151
  • 234
12
votes
6 answers

Download file using HtmlUnit

I am trying to download xls file for a website. When I click the link to download the file, I get a javascript confirm box. I handle it like below ConfirmHandler okHandler = new ConfirmHandler(){ public boolean handleConfirm(Page…
user367942
  • 251
  • 1
  • 3
  • 8
12
votes
3 answers

HTMLUnit : super slow execution?

I have been using HTMLUnit . It suits my requirements well. But it seems to be extremely slow. for example : I have automated the following scenario using HTMLUnit Goto Google page Enter some text Click on the search button Get the title of the…
Kanishka Dilshan
  • 724
  • 2
  • 10
  • 19
11
votes
3 answers

XPath to locate a cell with specific text parsing HTML tables

Hope someone out there can quickly point me in the right direction with my XPath difficulties. Current I've got to the point where I'm identifying the correct table i need in my HTML source but then I need to process only the rows that have the text…
David Brown
  • 3,021
  • 3
  • 26
  • 46
11
votes
6 answers

Is it possible to ignore JavaScript exceptions when working with WebDriver (HtmlUnit, Ruby bindings)

HtmlUnit throws exception and crash my test when I'm loading the page caps = Selenium::WebDriver::Remote::Capabilities.htmlunit(:javascript_enabled => true) driver = Selenium::WebDriver.for(:remote, :desired_capabilities => caps) driver.navigate.то…
boxx
  • 1,111
  • 2
  • 9
  • 15
11
votes
2 answers

Are Futures executed on a single thread? (Scala)

Using the implicit execution context in Scala, will each new future be computed on a single, dedicated thread or will the computation be divided up and distributed to multiple threads in the thread pool? I don't know if this helps, the background to…
11
votes
2 answers

Save image from url with HTMLUnit

Is it possible to save an image to hard disk with HTMLUnit by giving it the image URL? If so how? Regards!
Arya
  • 8,473
  • 27
  • 105
  • 175
10
votes
3 answers

How to setup HtmlUnit in an Eclipse project?

My project includes htmlunit jars and downloads some pages content. Executable jar (which includes libs, funct. of eclipse export) thereof, however, works only on the machine on which I created it (on different it doesn't execute). EDIT: It doesn't…
Jan Lycka
  • 111
  • 1
  • 1
  • 8
10
votes
2 answers

Java: how to setup htmlunit

I'm a pretty big noob to Java, but I would like try out htmlunit. I'm using netbeans as my IDE and I've created a project folder "hu1". Here is the structure for that folder: hu1 > nbproject > src > hu1 > test Now, I download htmlunit 2.7…
Joe
  • 303
  • 1
  • 4
  • 9
10
votes
2 answers

Get the changed HTML content after it's updated by Javascript? (htmlunit)

I'm having some trouble figuring out how to get the content of some HTML after javascript has updated it. Specifically, I'm trying to get the current time from US Naval Observatory Master Clock. It has an h1 element with the ID of USNOclk in which…
Zack Yoshyaro
  • 2,056
  • 6
  • 24
  • 46
9
votes
1 answer

HttpUnit/HtmlUnit equivalent for android

I'm looking for a browser-simulating library on android, which handles things like loading a website (http/https) Redirections: HTTP (3xx Status Codes), JavaScript, HMTL tags filling out html-forms easy html parsing (could fall back to JSoup for…
LangerJan
  • 165
  • 1
  • 9
9
votes
2 answers

Getting error "Provider com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl not found" in unit test but not in main program

I am building an application in C# which uses com.gargoylesoftware.htmlunit.WebClient to access and retrieve information from webpages. My application runs fine from the main project but when I try to build unit tests to test the project classes I…
hello-klol
  • 735
  • 10
  • 20
9
votes
0 answers

HtmlUnit download attachments

I need to save files from websites Using HtmlUnit. I am currently navigating to pages that have several anchors that use javascript onClick()="DownloadAttachment('attachmentId')" to get the files. The files can be of pretty much any type ( xls, doc,…
TheBeeKeeper
  • 225
  • 2
  • 12
9
votes
1 answer

HtmlUnit css not applied properly

I try to save the google page using HtmlUnit. But I can't get proper UI. When I check the saved page codes style tags are empty. My code is here. public static void main(String[] args) throws IOException { FileUtils.cleanDirectory(new…
Anbu
  • 490
  • 6
  • 20