java - Submitting a form using html unit -
i want login https://pacer.login.uscourts.gov/csologin/login.jsf. have used html unit submitting login form. here code:
public void submittingform() throws exception { final webclient webclient = new webclient(); // first page final htmlpage page1 = webclient.getpage("https://pacer.login.uscourts.gov/csologin/login.jsf"); // form dealing , within form, // find submit button , field want change. final htmlform form = page1.getformbyname("login"); // final htmlsubmitbutton button = form.getbuttonbyname("login:j_idt184"); final htmltextinput textfield = form.getinputbyname("login:loginname"); final htmltextinput textfield1 = form.getinputbyname("login:password"); // change value of text field textfield.setvalueattribute("xxx"); textfield1.setvalueattribute("xxx"); // submit form clicking button , second page. final htmlpage page2 = form.getbuttonbyname("login:j_idt184").click(); system.out.println(page2.astext()); webclient.closeallwindows(); }
but coutinue showing same error:
exception in thread "main" java.lang.illegalaccesserror: class com.gargoylesoftware.htmlunit.javascript.regexp.htmlunitregexpproxy$fixedsubstring cannot access superclass net.sourceforge.htmlunit.corejs.javascript.regexp.substring @ java.lang.classloader.defineclass1(native method) @ java.lang.classloader.defineclass(classloader.java:791) @ java.security.secureclassloader.defineclass(secureclassloader.java:142) @ java.net.urlclassloader.defineclass(urlclassloader.java:449) @ java.net.urlclassloader.access$100(urlclassloader.java:71) @ java.net.urlclassloader$1.run(urlclassloader.java:361) @ java.net.urlclassloader$1.run(urlclassloader.java:355) @ java.security.accesscontroller.doprivileged(native method) @ java.net.urlclassloader.findclass(urlclassloader.java:354) @ java.lang.classloader.loadclass(classloader.java:423) @ sun.misc.launcher$appclassloader.loadclass(launcher.java:308) @ java.lang.classloader.loadclass(classloader.java:356) @ com.gargoylesoftware.htmlunit.javascript.htmlunitcontextfactory.makecontext(htmlunitcontextfactory.java:227) @ net.sourceforge.htmlunit.corejs.javascript.context.enter(context.java:439) @ net.sourceforge.htmlunit.corejs.javascript.context.call(context.java:535) @ net.sourceforge.htmlunit.corejs.javascript.contextfactory.call(contextfactory.java:538) @ com.gargoylesoftware.htmlunit.javascript.javascriptengine.initialize(javascriptengine.java:157) @ com.gargoylesoftware.htmlunit.webclient.initialize(webclient.java:1141) @ com.gargoylesoftware.htmlunit.webwindowimpl.setenclosedpage(webwindowimpl.java:109) @ com.gargoylesoftware.htmlunit.html.htmlparser.parse(htmlparser.java:200) @ com.gargoylesoftware.htmlunit.html.htmlparser.parsehtml(htmlparser.java:179) @ com.gargoylesoftware.htmlunit.defaultpagecreator.createhtmlpage(defaultpagecreator.java:221) @ com.gargoylesoftware.htmlunit.defaultpagecreator.createpage(defaultpagecreator.java:106) @ com.gargoylesoftware.htmlunit.webclient.loadwebresponseinto(webclient.java:433) @ com.gargoylesoftware.htmlunit.webclient.getpage(webclient.java:311) @ com.gargoylesoftware.htmlunit.webclient.getpage(webclient.java:373) @ com.gargoylesoftware.htmlunit.webclient.getpage(webclient.java:358) @ htmlunit.htmlunit.submittingform(htmlunit.java:63) @ htmlunit.htmlunit.main(htmlunit.java:28) java result: 1
how overcome above error , successfull login above url.i using following jar in code: htmlunit2.9jar,commons-code.jar,etc. jar need avoid above error.
please provide suggestion.
thanks
atul
the htmlunit installation have on system includes both htmlunit-2.15.jar (let's call "main" jar) , htmlunit-core-js-2.15.jar (let's call "corejs" jar). looking inside 2 jars, can see main jar has com.gargoylesoftware.htmlunit.javascript.regexp.*
, while corejs jar has net.sourceforge.htmlunit.corejs.javascript.regexp.*
:
> in htmlunit-2.15.jar htmlunit-core-js-2.15.jar; echo "===== $i ====="; unzip -l $i| grep regexp; done; ===== htmlunit-2.15.jar ===== 0 06-02-2014 19:53 com/gargoylesoftware/htmlunit/javascript/regexp/ 768 06-02-2014 19:53 com/gargoylesoftware/htmlunit/javascript/regexp/htmlunitregexpproxy$fixedsubstring.class 1846 06-02-2014 19:53 com/gargoylesoftware/htmlunit/javascript/regexp/htmlunitregexpproxy$regexpdata.class 11530 06-02-2014 19:53 com/gargoylesoftware/htmlunit/javascript/regexp/htmlunitregexpproxy.class 1549 06-02-2014 19:53 com/gargoylesoftware/htmlunit/javascript/regexp/regexpjstojavaconverter$tape.class 3777 06-02-2014 19:53 com/gargoylesoftware/htmlunit/javascript/regexp/regexpjstojavaconverter.class ===== htmlunit-core-js-2.15.jar ===== 0 05-30-2014 10:28 net/sourceforge/htmlunit/corejs/javascript/regexp/ 944 05-30-2014 10:28 net/sourceforge/htmlunit/corejs/javascript/regexp/compilerstate.class 712 05-30-2014 10:28 net/sourceforge/htmlunit/corejs/javascript/regexp/globdata.class 42350 05-30-2014 10:28 net/sourceforge/htmlunit/corejs/javascript/regexp/nativeregexp.class 6850 05-30-2014 10:28 net/sourceforge/htmlunit/corejs/javascript/regexp/nativeregexpctor.class 1077 05-30-2014 10:28 net/sourceforge/htmlunit/corejs/javascript/regexp/rebacktrackdata.class 700 05-30-2014 10:28 net/sourceforge/htmlunit/corejs/javascript/regexp/recharset.class 819 05-30-2014 10:28 net/sourceforge/htmlunit/corejs/javascript/regexp/recompiled.class 1245 05-30-2014 10:28 net/sourceforge/htmlunit/corejs/javascript/regexp/reglobaldata.class 687 05-30-2014 10:28 net/sourceforge/htmlunit/corejs/javascript/regexp/renode.class 918 05-30-2014 10:28 net/sourceforge/htmlunit/corejs/javascript/regexp/reprogstate.class 14443 05-30-2014 10:28 net/sourceforge/htmlunit/corejs/javascript/regexp/regexpimpl.class 1072 05-30-2014 10:28 net/sourceforge/htmlunit/corejs/javascript/regexp/substring.class
so suspect including main jar in $classpath, not corejs jar. thus, solve problem, have find corejs jar , include in $classpath.
normally, once installed, these 2 jars live in same directory. so, if case you, easier use wildcard syntax in $classpath both of them in 1 shot.
Comments
Post a Comment