I have started learning HTTPUNIT and found one basic example.
In this example it will visit this site. And it will search for the link containing HTTPUNIT. And it will print the number of links on the HTTPUNIT. I tried this example on my machine and it works.
WebConversation wc = new WebConversation();
WebRequest request = new GetMethodWebRequest( "http://www.meterware.com" );
WebResponse response = wc.getResponse( request );
WebLink httpunitLink = response.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "HttpUnit" );
response = httpunitLink.click();
System.out.println( "The HttpUnit main page contains " + response.getLinks().length + " links" );
Now i have changed the code to
WebConversation wc = new WebConversation();
WebRequest request = new GetMethodWebRequest( "http://www.google.com" );
WebResponse response = wc.getResponse( request );
WebLink httpunitLink = response.getFirstMatchingLink( WebLink.MATCH_CONTAINED_TEXT, "News" );
response = httpunitLink.click();
System.out.println( "The HttpUnit main page contains " + response.getLinks().length + " links" );
And now it is giving the error below.
ConversionError: The undefined value has no properties. (httpunit; line 4)
Why it is not able to visit google news and get the number of links?
Thank you in advance.
The google home page is rendered from JavaScript.
HTTPUNIT has partial support for JavaScript. If you need to test pages with heavy JavaScript, take a look at Selenium