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
9
votes
2 answers

How to detect when Selenium loads a browser's error page

Is there a universal way to detect when a selenium browser opens an error page? For example, disable your internet connection and do driver.get("http://google.com") In Firefox, Selenium will load the 'Try Again' error page containing text like…
sam-6174
  • 3,104
  • 1
  • 33
  • 34
9
votes
5 answers

HTMLUnit: change User Agent string

I'm using HtmlUnit in my Java project in order to test a web page that has got Javascript inside. My code clicks a button that calls a Javascript function, wich redirect the user to another page (like link shortener services). This is the…
Angelo
  • 907
  • 3
  • 16
  • 33
9
votes
1 answer

HtmlUnit: one WebClient per thread - is it thread safe?

I have many threads. Each thread creates and uses it's own WebClient (HtmlUnit framework). No one thread uses WebClient's instance from other thread. Is it thread safe?
den123
  • 793
  • 1
  • 12
  • 27
8
votes
1 answer

How to get a HTML page using HtmlUnit

I know you may think this question is stupid, but I need to use HtmlUnit. However, it returns a page either as XML or as text. I don't how to get the pure HTML (the same as the source code that browsers return) I need this, because I need to use…
Afshin Moazami
  • 2,092
  • 5
  • 33
  • 55
8
votes
1 answer

Passing basic auth credentials with every request with HtmlUnit WebClient

I'm trying to write a simple smoke test for a web application. The application normally uses form based authentication, but accepts basic auth as well, but since the default is form based authentication, it never sends an authentication required,…
Jens Schauder
  • 77,657
  • 34
  • 181
  • 348
8
votes
4 answers

How to load ajax with HtmlUnit?

import java.io.IOException; import java.net.MalformedURLException; import java.util.List; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; import com.gargoylesoftware.htmlunit.WebClient; import…
Иван Бишевац
  • 13,811
  • 21
  • 66
  • 93
8
votes
6 answers

HtmlUnit - Convert an HtmlPage into HTML string?

I'm using HtmlUnit to generate the HTML for various pages, but right now, the best I can do to get the page into the raw HTML that the server returns is to convert the HtmlPage into an XML string. This is somewhat annoying because the XML output is…
Peter
  • 837
  • 3
  • 14
  • 19
8
votes
2 answers

No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier when using htmlunit in Android Studio Project

I am using htmlunit 2.36.0 in my Android Studio Project. I successfully compiled the apk but I am getting some runtime errors when I try to get a webpage. Before, I was getting the following error: java.lang.BootstrapMethodError: Exception from…
DeborahAnn
  • 191
  • 1
  • 11
8
votes
1 answer

How reliable is HtmlUnitDriver?

Obviously, the answer to the question depends on a number of environmental factors. In general, I'm wondering what people's experiences are with HtmlUnitDriver as a reliable tool that can be "trusted" to navigate a website basically the same way…
Dan Tao
  • 125,917
  • 54
  • 300
  • 447
8
votes
2 answers

htmlunit java change input text

I use htmlunit. How i can set value of text input if it does not have an attribute 'value' ? I tried this, but nothing ((HtmlTextInput)…
jim
  • 81
  • 1
  • 1
  • 2
8
votes
3 answers

HtmlUnit close all windows memory leak

HtmlUnit does not appears to close windows in the webclient and thus creating a memory leak. I am trying to get a page with HtmlUnit and pass it off to JSoup for parsing. I am aware that JSoup can connect to a page but I need to use this approach as…
user1625233
  • 253
  • 3
  • 9
8
votes
2 answers

How to click on a javascript button in htmlunit

I'm trying to click on a search button in this website: http://www.amadeusepower.com/trek/portals/trek/default.aspx?Culture=en-US The button is in here somewhere
ManahManah
  • 263
  • 2
  • 5
  • 17
8
votes
3 answers

In Java and HtmlUnit, how to wait for a resulting page to finish loading and download it as HTML?

HtmlUnit is an awesome Java library that allows you to programatically fill out and submit web forms. I'm currently maintaining a pretty old system written in ASP, and instead of manually filling out this one web form on a monthly basis as I'm…
Matthew Quiros
  • 13,385
  • 12
  • 87
  • 132
8
votes
4 answers

Login Using HtmlUnit

I am very very new to HtmlUnit. I want to know do I am able to login to a site using htmlunit and perform some operations in the site for example I want to login to my office portal and to aplly a leave.I am using html unit and it shows some…
Renjith K N
  • 2,613
  • 2
  • 31
  • 53
7
votes
1 answer

HTMLUNIT getformbyname with no form name specified in the website

I'm trying to clcik a button on a website using HTMLUNIT i followed this tutorial http://htmlunit.sourceforge.net/gettingStarted.html but it requires a form name. The website I'm trying to do has this page source.
shinra tensei
  • 693
  • 5
  • 20
  • 39