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
66
votes
18 answers

Turning HtmlUnit Warnings off

Do you know how can I turn Warnings, Notes, Errors in HtmlUnit off?
oneat
  • 10,778
  • 16
  • 52
  • 70
47
votes
6 answers

Selenium vs HtmlUnit?

I am trying to understand testing framework better and been looking into Selenium. I've used HTMLUnit before, mainly when I needed to scrape some information off website or the likes. In the context of writing test automation, what's the advantage /…
TS-
  • 4,311
  • 8
  • 40
  • 52
36
votes
2 answers

Android Web Scraping with a Headless Browser

I have spent a day on researching a library that can be used to accomplish the following: Retrieve the full contents of a webpage like in the background without rendering result to a view. The lib should support pages that fires off ajax requests…
Pierre
  • 1,607
  • 3
  • 21
  • 33
33
votes
3 answers

HtmlUnitDriver (HtmlUnit) vs GhostDriver (PhantomJS)?

We are in the middle of choosing our headless browser driver solution that will be some implementation of Selenium WebDriver. There is the GhostDriver, which leverages the PhantomJS in the backend on the one side and HtmlUnitDriver which based on…
Johnny
  • 14,397
  • 15
  • 77
  • 118
27
votes
4 answers

How to overcome an HTMLUnit ScriptException?

I got a problem with a line of code that probably triggers some js function e couse an exception, how can i fix this? box.setText(link.toString()); client.waitForBackgroundJavaScriptStartingBefore(10000); box.dblClick(); //this line cause the…
user3054975
  • 281
  • 1
  • 3
  • 3
25
votes
3 answers

How to use HtmlUnit in Java to select an element from a drop down box?

I'm using HtmlUnit in Java to navigate to a web page. From that webpage i need to log in and then go from there. I know how to type in the user name and password but then there is a dropdown box where i need to select one of the options. How do i…
Peter
  • 5,071
  • 24
  • 79
  • 115
25
votes
3 answers

.net equivalent of htmlunit?

Does anybody know if there is a .net equivalent of htmlunit or similar library? I've heard that people have used IKVM to convert the htmlunit library. But I have also heard that the converted code is slow. Requirements: Headless browser Support…
mike
  • 251
  • 1
  • 3
  • 4
23
votes
4 answers

HTMLUnit doesn't wait for Javascript

I have a GWT based page that I would like to create an HTML snapshot for it using HtmlUnit. The page loads using Ajax/JavaScript information on a product, so for about 1 second there is a Loading... message and then the content appears. The problem…
Joly
  • 3,218
  • 14
  • 44
  • 70
22
votes
6 answers

Alternative to HtmlUnit

I have been researching about the headless browsers available till to date and found HtmlUnit being used pretty extensively. Do we have any alternative to HtmlUnit with possible advantage compared to HtmlUnit? Thanks Nayn
Nayn
  • 3,594
  • 8
  • 38
  • 48
20
votes
4 answers

How to create HtmlUnit HTMLPage object from String?

This question was asked once already, but the API changed I guess and the answers are no valid anymore. URL url = new URL("http://www.example.com"); StringWebResponse response = new…
lisak
  • 21,611
  • 40
  • 152
  • 243
19
votes
3 answers

HtmlUnit ignore JavaScript errors?

I'm trying to traverse through a website but on one of their pages I get this error: EcmaError: lineNumber=[671] column=[0] lineSource=[null] name=[TypeError] sourceName=[https://reservations.besodelsolresort.com/asp/CalendarPopup.js]…
cantread
  • 405
  • 1
  • 7
  • 14
17
votes
2 answers

Htmlunit on Android application

Has anybody gotten HTMLUnit (or HtmlUnitDriver) to work on Android apps? This is the problem: I am getting the following error message: 11-26 16:27:26.617: E/AndroidRuntime(1265): java.lang.NoClassDefFoundError: org/w3c/dom/css/CSSRule This is…
Ulises
  • 13,229
  • 5
  • 34
  • 50
16
votes
5 answers

HtmlUnit, how to post form without clicking submit button?

I know that in HtmlUnit i can fireEvent submit on form and it will be posted. But what If I disabled javascript and would like to post a form using some built in function? I've checked the javadoc and haven't found any way to do this. It is…
user967639
  • 161
  • 1
  • 1
  • 3
16
votes
7 answers

Can't turn off HtmlUnit logging messages

I'm using HtmlUnit to interact with a web page that interacts with the server via Ajax. Soon after the Ajax code starts, HtmlUnit produces these two log messages: WARNING: Ignoring XMLHttpRequest.setRequestHeader for Content-length: it is a…
Sean
  • 29,130
  • 4
  • 80
  • 105
16
votes
1 answer

Prevent HtmlUnit 2.13 from executing JavaScript

Here is my code to get the page: WebClient webClient = new WebClient(); HtmlPage page = webClient.getPage(url); The problem is the webClient always executes javascript automatically and throws me a list of error. I just want to get the raw source.…
Triet Doan
  • 11,455
  • 8
  • 36
  • 69
1
2 3
99 100