0

My Java code using html unit is working perfectly fine as I need to open a webpage and fill a form and finally click submit. But when I tried to deploy Java code Jar in Unix, it's unable to find and click on the text input fields/buttons.

So please help regarding this. I am getting a Null Pointer Exception whenever i am trying to fetch an Element by Id,for example :

1) HtmlAnchor addr = (HtmlAnchor) page.getElementById("element_id");

2) page = addr.click();

Getting an error at line 2

I am just export the class as Runnable Jar file and running it on unix java -jar

Please help.

RendezAWS
  • 103
  • 9

1 Answers1

0

Usually, you could print page.asXml() to see how the page is seen.

You could have network connectivity difference, between running from the server and from your machine. Hostname vs 'localhost' can cause some differences too.

Waiting for background threads can differ between machines, please read this.

Also, please use latest version of HtmlUnit, you can print the used version.

Hope that helps

Ahmed Ashour
  • 5,179
  • 10
  • 35
  • 56
  • page.asXml() is returning me difference in no. of lines,through java i am getting code of about 6000 lines ,while through unix i got about 4000 lines only,also some tags and div's were missing. – RendezAWS May 09 '15 at 04:19
  • You can use the OSGi bundle in both your local machine and compare the result with unix, you can get from https://sourceforge.net/projects/htmlunit/files/htmlunit/2.16/ , also you can post the complete case so others can check. – Ahmed Ashour May 09 '15 at 09:32
  • Great that the answer was accepted, please vote it up if you find it useful. – Ahmed Ashour Sep 30 '15 at 16:13