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
0
votes
0 answers

How can I get the html code of the Dom element?

I use the class name to find the DomElement, how can I find the html code of that class using that DomElement or any other way? DomElement htmlEl = currentPage.querySelector(".next"); Thank you.
OPfan
  • 1,625
  • 2
  • 13
  • 18
0
votes
1 answer

How to include HtmlUnit in a Kotlin project

I'm trying to use HtmlUnit in a Kotlin project but I get the following error when I compile: Error:Kotlin: Supertypes of the following classes cannot be resolved. Please make sure you have the required dependencies in the classpath: class…
Johnny
  • 7,073
  • 9
  • 46
  • 72
0
votes
0 answers

spring-framework htmlunitwebdriver testing doesn't support ajax post?

I think the spring-framework webdriver(MockMvcHtmlUnitDriver) testing doesn't support POST parameter passing(or encoding) correctly. $.ajax(... method: 'POST', { data : {'param1' : 'param1Val', 'param2' : 'param2Val' } ...) then server expect the…
Anna
  • 1
  • 3
0
votes
1 answer

unable to setup HTMLUNIT in eclipse

Please assist me in setting up htmlunit with eclipse. I am tryning to fill a form and submit it through the code Here is my code import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlForm; import…
Mayank Vaid
  • 330
  • 1
  • 7
  • 18
0
votes
1 answer

JavaScript Exception in HtmlUnit when clicking at google result page

I want to use HtmlUnit (v2.21) to get some search result pages from google. This requires me to click on "people also looked for" link when searching for a person (right side, see example link), which triggers some JavaScript and changes the content…
0
votes
2 answers

HTMLunit fails to execute onclick mojarra script in href

Currently I am writing a Web-scraper based on HTMLunitfor harvesting specific Company names and details from the Hannovermesse trade fair exhibition website. I seem to have encountered a showstopper for my efforts, as i cannot get the page…
Helmut
  • 11
  • 3
0
votes
1 answer

How to provide a value for text field that does not have the value attribute in HtmlUnit?

The HTML element below is part of a form: I would like to pass a string to this element. I do not know how to pass a string without a value attribute.
cheyrico2
  • 359
  • 1
  • 3
  • 17
0
votes
0 answers

Htmlunit in Webservice

I am trying to create a web service that scrap data from JustDial. I am able to run the code when using a simple java application rather than Dynamic Web Project in the form of web service. WebClient client = new WebClient(); This is the line…
Gaurav Arora
  • 63
  • 1
  • 10
0
votes
1 answer

HtmlUnit Failed to fetch Page - javascript block

First I would like to mention that I am newbie to HtmlUnit. I am trying to fetch a webpage and than parse its content. URL: https://secure.fattal.co.il/BE_Results.aspx?Lang=heb&In=2016-08-07&Out=2016-08-11&Region=2&Rooms=1&Ad1=2&Ch1=0&Inf1=0 but I…
YyYo
  • 651
  • 5
  • 13
0
votes
1 answer

Java HtmlUnit click on anchor link does not work. How do I get the new page?

I'm trying to click on a "More" anchor tag on a website using HtmlUnit in order to expand a list until the more anchor tag does not exist. page = client.getPage(url); HtmlAnchor anchor; while((anchor = page.getFirstByXPath("//a[@class='load-more…
God Usopp
  • 331
  • 1
  • 6
  • 18
0
votes
0 answers

HtmlUnit works different when i debug and run my code

I'm using HtmlUnit to parse html with js code. The structure of the page is(using Chrome Developer Tools): And my code is as follow: WebClient wc=new WebClient(BrowserVersion.INTERNET_EXPLORER_11); wc.getOptions().setUseInsecureSSL(true); …
chou
  • 344
  • 3
  • 17
0
votes
0 answers

Clicking on javascript anchor with htmlunit does not fetch response

So, I collected all the anchors of a Page in a list of HtmlAnchors. List downloadLinks = (List) loggedIn.getByXPath("//*[@id='ctl00_ContentPlaceHolder1_rgdProduction_ctl00']//a"); And then, I went in a loop to click on each anchor in…
0
votes
2 answers

Scraping our site to check for Javascript errors

I am kind of desperate here. For a couple of days I have been trying to create a web scraper that can go through our website and check for Javascript errors. The big problem is that I only know Java and it seems that GhostDriver isn't maintained…
Homewrecker
  • 1,076
  • 1
  • 15
  • 38
0
votes
1 answer

HTMLunit browser automation causes SSL error

I am writing a simple piece of Java code, to check my external IP and update my DNS entries if it has changed. I use NetBeans and HTMLunit. The first part of the code works OK. My code gets the proper External IP address from WhatIsMyIp.com The…
0
votes
1 answer

HtmlUnit: click on anchor does not trigger any event

im trying to click on this link:
Martin
  • 55
  • 1
  • 6