Calling Javascript on web page from Java -


My goal is to connect to an OWA page (Microsoft Office Web Access - basically an email client) and log-in,

To login, I need to fill in the username and password fields and call some javascript function for which I know the name and headers.

How do I:

  1. Get the DOM for the page?
  2. Update DOM to fill input text fields?
  3. Call the JavaScript function?
  4. Get a new URL for the page I'm redirected to?

By now I am able to connect to a webpage and load its page source using the following Java code:

  // welcome page Open the connection to callback.status ("Open the connection ..."); URL Connection Connection = Null; Try {connection = url.openConnection (); } Grip (IOException pre) {New exception throw ("I / O URL connection while attempting problem"); } Connection.setDoInput (true); // Open Input Stream Website Callback for Opening Website.States ("Opening Data Stream ..."); InputStream input = null; Try {input = connection.getInputStream (); } Hold (IOException pre) {New exception throw ("I / O problem while opening data stream"); } // read website content callback.status ("Reading site ..."); String content = ""; Byte [] buffer = new byte [100]; Int totalBytesRead = 0; Int BitesRad = 0; Try {while ((bytesread = input. Reed (buffer))! = -1) {string newContent = new string (buffer, 0, bytes read); Content + = newContent; }} Hold (IOException pre) {new exception throw ("I / O problem when reading website"); } System.out.println (content); The result is that the complete page source output on the console - great I also tried to parse the page to get a DOM object, which I used to enter my username and password field. Can find the following:  
  XMLParserConfiguration config = new XML11DTDConfiguration (); Domparser parser = new dumppars (config); InputSource inputSource = new input source (input); InputSource.setByteStream (input); Try {Parser.parse (inputSource); } Hold (SAXParseException pre) {} document document = parser.getDocument (); VisitNode (document, 0);  

But I'm getting SAXParseException :: 6:62: White id between public id and system id is required.

It seems that this line is to blame:

   

So I may need to change the configuration of that DOMParser, which should be light in any way and the white space requirement will be "Forgive".

The post text "itemprop =" text ">

Do you want to function as a GUI-less webbrowser programmaticaly? Use, that's what it advertises with itself. / P>

HtmlUnit is "GUI-less Browser for Java Programs" It provides the model of HTML documents and an API that allows you to open pages, fill out forms, links, etc. ... like you do in your "normal" browser.

This is a good JavaScript support (which is constantly improving) and is capable of dealing with quite complex AJAX libraries, either using Firefox or Internet Explorer based on configuration.

Li>


Comments