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

Android: CSS Error when using HTML Unit & Eclipse

I am using Html Unit to go to a webpage, fill in some forms, and click a button to get to the next webpage. That new webpage, (called newPage in my code) is what I'm extracting the html source from. This method works perfectly in Netbeans (although…
Kgrover
  • 2,106
  • 2
  • 36
  • 54
5
votes
1 answer

How do I get HtmlUnit to work under Android?

Here is my code: import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlPage; final WebClient webClient = new WebClient(); final HtmlPage startPage = webClient.getPage("http://htmlunit.sf.net"); And this…
texasman1979
  • 473
  • 1
  • 6
  • 17
5
votes
1 answer

How do you emulate the browser's back button in HtmlUnit?

I have not found a clear and obvious suggestion to emulate the browser's 'Back' button in HtmlUnit. Have you done this? If so, how? The best thing I've come up with is to execute javascript on the current page: ScriptResult result =…
fooMonster
  • 987
  • 2
  • 9
  • 23
5
votes
1 answer

How to get element by Xpath in HtmlUnit

I am trying to search Amazon. I want to choose category, for ex. Books, type some search criteria, for ex. java and to click Go button. My problem is clicking the Go button. I've got exception: Exception in thread "main"…
Иван Бишевац
  • 13,811
  • 21
  • 66
  • 93
5
votes
1 answer

Why would HtmlUnitDriver not Locate WebElements but FirefoxDriver able to locate the same WebElements

I have a question. What makes FirefoxDriver be able to locate WebElements and click on them in a java code but when running the same code with HtmlUnitDriver the same WebElements are not located. Also when running the same code on HtmlUnit(applying…
5
votes
4 answers

HtmlUnit Android: NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier

I'm trying to run HtmlUnit on Android. I think this answer used to work with the older libs, but not anymore. The other threads related to this question are not about Kotlin on Android or are outdated. Consider below…
Jim Clermonts
  • 1,694
  • 8
  • 39
  • 94
5
votes
1 answer

How do I get Html created by javascript using HtmlUnit in Java and then parse it with Jsoup?

I am trying to access some content on a web page that is created by some Javascript. However, the content that I wish to access is created by the javascript after the page has loaded so this chunk of Html source is no where to be found when I try…
THow
  • 119
  • 9
5
votes
2 answers

How to get Atomic Value between Element Nodes using XPath

I want to select only the atomic values inside a node. For example, the "here" text in the following: here When I use Xpath in Java, it returns some sort of object/array, such as [DomNode[here]] I just want the text…
Allen Gingrich
  • 5,608
  • 10
  • 45
  • 57
5
votes
1 answer

Open link from with HtmlUnit Java

I have an html file that has this part: NAME How can I open this link on href with HtmlUnit? My code: final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_11); final…
5
votes
1 answer

How to extract the text without HTML tags out of a webpage using HtmlUnit?

I'm just getting started with HTMLUnit and what I'm looking to do is take a webpage and extract out the raw text from it minus all the html markup. Can htmlunit accomplish that? If so, how? Or is there another library I should be looking at? for…
James
  • 15,085
  • 25
  • 83
  • 120
5
votes
3 answers

Java – How can I Log into a Website with HtmlUnit?

I am writing a Java program to log into the website my school uses to post grades. This is the url of the login form: https://ma-andover.myfollett.com/aspen/logon.do This is the HTML of the login form:
Irregular Square
  • 79
  • 1
  • 1
  • 7
5
votes
1 answer

Errors while trying to parse ember app with HtmlUnit

So I have an Ember app and I need to take a snapshot for crawling purposes. The Ember app uses Google+ API for singing in. It also has a Youtube video embedded in the index page. I use HtmlUnit v2.15. I'm using the following code to initialize…
Bogdan Zurac
  • 6,348
  • 11
  • 48
  • 96
5
votes
1 answer

HtmlUnit - PKIX path building failed: unable to find valid certification path to requested target

I have a JAVA EE webapp on Glassfish using a GoDaddy SSL certificate. The HTTP listener redirects to the HTTPS one. I'm trying to get HtmlUnit to fetch a page from the webapp for Googlebot crawler. The code works as intended on the staging server…
Bogdan Zurac
  • 6,348
  • 11
  • 48
  • 96
5
votes
0 answers

Lightweight headless browser suitable for multithreading

I have coded several projects with Selenium, which worked perfectly for all my needs, then I needed a headless browser and coded just a small test using PhantomJS and it worked just fine. However, PhantomJS uses way too much memory for me to launch…
TH Todorov
  • 1,129
  • 11
  • 26
5
votes
1 answer

HtmlUnit - dynamically loaded JavaScript not running

I'm trying to write some automated tests of a website using HtmlUnit. Our web pages load two JavaScripts, one of which then loads several other JavaScripts dynamically into the DOM. These JavaScripts then do some UI initialization. My problem is…
James Kingsbery
  • 7,298
  • 2
  • 38
  • 67