java - HtmlUnit throws many exceptions on clicking one button -


i'm trying create program signs in yahoo account. i'm using htmlunit in java, when program trying cick sign in button throws large number of various exceptions.

the button form is:

<form method="post" action="https://login.yahoo.com/config/login?" autocomplete="" name="login_form" onsubmit="return hash2(this)">     <input type="hidden" name=".tries" value="1"/>     <input type="hidden" name=".src" value=""/>     <input type="hidden" name=".md5" value=""/>     <input type="hidden" name=".hash" value=""/>     <input type="hidden" name=".js" value=""/>     <input type="hidden" name=".last" value=""/>     <input type="hidden" name="promo" value=""/>     <input type="hidden" name=".intl" value="us"/>     <input type="hidden" name=".bypass" value=""/>     <input type="hidden" name=".partner" value=""/>     <input type="hidden" name=".u" value="eqn7kn96q7irv"/>     <input type="hidden" name=".v" value="0"/>     <input type="hidden" name=".challenge" value="rtrqt.vavybejgxmmpkh0sqyx5mz"/>     <input type="hidden" name=".yplus" value=""/>     <input type="hidden" name=".emailcode" value=""/>     <input type="hidden" name="pkg" value=""/>     <input type="hidden" name="stepid" value=""/>     <input type="hidden" name=".ev" value=""/>     <input type="hidden" name="hasmsgr" value="0"/>     <input type="hidden" name=".chkp" value="y"/>     <input type="hidden" name=".done" value="http://my.yahoo.com"/>     <input type="hidden" name=".pd" value="_ver=0&c=&ivt=&sg="/>     <input type="hidden" name="pad" id="pad" value="3"/>     <input type="hidden" name="aad" id="aad" value="3"/>     <div id="inputs">     <div id="fun"/>     <div id="persistency">     <div id="submit">         <button type="submit" id=".save" name=".save" class="primarycta" tabindex="5"> sign in </button>     </div> </form> 

and java code:

import com.gargoylesoftware.htmlunit.webclient; import com.gargoylesoftware.htmlunit.html.htmlform; import com.gargoylesoftware.htmlunit.html.htmlpage; import com.gargoylesoftware.htmlunit.browserversion; import com.gargoylesoftware.htmlunit.page; import com.gargoylesoftware.htmlunit.refreshhandler; import com.gargoylesoftware.htmlunit.html.htmlbutton; import java.io.ioexception; import java.net.url;  public class virtualwebbrowser {      public static void clickauthorizebutton(string url, string login, string password) throws exception {          webclient webclient = new webclient(browserversion.firefox_3_6);         webclient.setthrowexceptiononscripterror(false);          webclient.setrefreshhandler(new refreshhandler() {             public void handlerefresh(page page, url url, int arg) throws ioexception {                 system.out.println("handlerefresh");             }         });          htmlpage loginpage = (htmlpage) webclient.getpage(url);         htmlform liginform = loginpage.getformbyname("login_form");          liginform.getinputbyname("login").setvalueattribute(login);         liginform.getinputbyname("passwd").setvalueattribute(password);          htmlbutton signinbutton = liginform.getbuttonbyname(".save");         htmlpage nextpage = (htmlpage) signinbutton.click();          webclient.closeallwindows();     } } 

all exceptions in line htmlpage nextpage = (htmlpage) signinbutton.click();

after line program logged in yahoo account these exceptions somehow affects program work works unstably. should avoid situation or @ least catch exceptions?

from errors pasted looks 1 of cases htmlunit javascript implementation differs 1 in browser. wouldn't surprised if yahoo didn't want people perform automatic login properties.

instead of wrestling javascript here try following things:

  1. look @ http communication using sniffer (like httpfox) , try send login request using httpurlconnection or httpclient.
  2. see if can login using api. know yahoo provides openid, might provide oauth authentication, see http://developer.yahoo.com/oauth/
  3. use selenium login using real browser.

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -