java - HtmlUnit onclick execution download file -
so here's deal:
accessing webpage(using htmlunit) on there's button. programatically click button(big mads hansen)
list l = page.getbyxpath( "//input[@type='submit' , @value='save xml']" ); ((htmlsubmitinput)l.get(0)).click();
the button has onclick event, following:
onclick="document.forms[0].action="calcsavexml_bg#pos";document.forms[0].submit()"
when click button through browser, given chance save xml file on hard drive.
thing is, want able xml file programatically. can done?
ok figured out. in case someone's interested:
list l = page.getbyxpath( "//input[@type='submit' , @value='save xml']" ); xmlpage result = ((htmlsubmitinput)l.get(0)).click(); string xml = result.getcontent(); try { documentbuilderfactory dbf = documentbuilderfactory.newinstance(); documentbuilder db = dbf.newdocumentbuilder(); document doc = db.parse( new java.io.bytearrayinputstream( xml.getbytes( "utf-8" ) ) ); doc.getdocumentelement().normalize(); //actual work going here } catch (exception e) { e.printstacktrace(); }
Comments
Post a Comment