htmlunit

Download a non html file with HtmlUnit

I'm writing a JUnit test that involves the downloading of a file from the web app. How do I do that with HtmlUnit? ...

How to delete cookies?

I want to delete cookies programmatically. More specifically, I am using HtmlUnit with Java to automate browser operations. After performing some operations I want to clear cookies so that my subsequent operations make sense. How can I clear cookies through HtmlUnit or through Java or through any other way automatically. ...

Error in simple Java application

Just playing around with java trying to learn it etc. Here is my code so far, using HtmlUnit. package hsspider; import com.gargoylesoftware.htmlunit.WebClient; /** * @author */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { System.out.println("...

How to navigate to another page after calling click?

I am trying to get all the main links, then click on them and navigation to the page: WebClient client = new WebClient(); HtmlPage page = client.getPage(url); // Get all links with a href of www.example.com/pages/1_ List<HtmlAnchor> links = (List<HtmlAnchor>) page.getByXPath("//a[href='www.example.com/pages/1_*'"); ...

Does this xpath look correct?

page.getByXPath("//*[@href='http://www.example.com/index.do/abc/1_*'"); Do I need to escape any characters? I am trying to get all ahref links on the page that have the pattern of: http://www.example.com/index.do/abc/1_ so these should all be retrieved: http://www.example.com/index.do/abc/1_asdf-asdfasdf http://www.example.com/ind...

return all the HtmlPage's HTML

I want the entire HTML for a given HtmlPage object. What property should I use? ...

clicking on submit button using php

Hi, I have a webpage with a submit button and I would like php to parse the webpage and click the submit button and get the response (it can be a link or another html page.) Is there any way to click a submit button using php? I know there is something like htmlunit for java that allows one to pro-grammatically fill the form fields an...

is it possible to load a HtmlPage from a string ?

I have stored a webpage's HTML in the database. I want to take advantage of HtmlUnit's ability to find/reference DOM elements. Is it possible to load the HtmlPage object from a string (via a database column)? ...

Using HtmlUnit, I have a HtmlTableRow, how can I get all its content as a string value?

I am using HtmlUnit. I have an object of HtmlTableRow type, and I want to dump all of the content to a variable, how can I do this? i.e. just want to get the HTML like: <tr><td>....</td></tr> ...

How to execute random Javascript code on a web page?

Hello. I'm using htmlunit to test some pages and I'd like to know how can I execute some javascript code in the context of the current page. I'm aware that the docs say I'd better emulate the behavior of a user on a page, but it isn't working this way :( (I have a div which has an onclick property, I call its click method but nothing hap...

Can't click on a youtube AJAX link with HtmlUnit.

Hello, I'm trying to use htmlunit to click on a link in youtube. Here's the code: HtmlPage page = webClient.getPage("http://www.youtube.com"); HtmlAnchor link = page.getFirstByXPath("//a[contains(@href, 'accounts/ServiceLogin?')]"); page = link.click(); HtmlForm form = page.getFirstByXPath("//form[@id='gaia_loginform']"); form.getInpu...

In htmlunit, how can I get the request, that would be sent on clicking an element?

Hello, I want to find a way to get the settings of the request that would be sent if I clicked a certain link. I want to send the request after making some modifications. Is that possible? Answering the comments, right now I want to change the headers sent, but post values or target url may be of interest too. I want to grab the request...

htmlunit cookie/refer question

Hi. Testing out the java HtmlUnit lib. Trying to figure out if there's a way to set/delete the cookie file (cookiejar) used by the webclient object.. I've searched multiple docs, as well as the HtmlUnit API with no luck, so I'm assuming I'm missing something. Also, is there a way to see the headers (request/respnse/referer) being xfer...

How to remove cookies from a headless browser provided by HtmlUnit in Java?

I am using HtmlUnit headless browser to access websites. Can the cookies sent by those websites store on my computer when I use that headless browser? If yes, then what's the location where these cookies get saved and how can I remove it through HtmlUnit? ...

HtmlUnit doubts regarding cookies and windows

If the HtmlUnit stores cookies in memory then Will HtmlUnit respond the server with cookies? When the HtmlUnit session terminates? Will it terminate when i call webclient.closeWindow()? As acc. to the HtmlUnit docs, WebClient represents a browser, so Is it represent a mutiple-windows browser (like IE7 in which we can open multiple tab...

Embedding Tomcat and issuing requests to the deployed application

OK, I'm completely stuck. I want to run Tomcat in embedded mode so I can test an application without running the server in a separate process. I'm missing something simple, stupid, and important, and I need your help to see it. This test fails with an HTTP error 400, Bad Request. I've tried MemoryProtocolHandler, context.invoke(), ... I...

Problem in HtmlUnit API for Java (Headless Browser)?

I am using HtmlUnit headless browser to browse this webpage (you can see the webpage to have a better understanding of the problem). I have set the select's value to "1" by the following commands final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_7); try { // Configuring the webClient web...

How to convert an <img... in html to byte [] in Java

I have opened a webpage in HtmlUnit headless browser. Now that webpage contains a image html tag as follows: <img src="..." /> So I want that image only. But the problem is that the same src URL of the image shows diff. image each time. Means, if we refresh the img src URL, then it shows diff. image each time. So how to get the image...

Using HtmlUnit/HttpUnit under GAE

Hi, I'm trying to load the DOM of web pages in my application (running under Google App Engine), using HtmlUnit, HttpUnit or any similar library. Did anyone manage to do something similar? Thanks Gilad ...

How to generate multiple impressions on a hyperlink through HtmlUnit in JAVA?

I am using the headless browser provide by HtmlUnit I have loaded a webpage in a webClient. Now I want to generate mulitple impressions on a hyperlink (on the loaded webpage) just like we hover our mouse cursor on a link various times on a link in a webpage in a real web browser. How can I do that through HtmlUnit? ...