Advertisement
madhawaseeeee

vvv

Oct 23rd, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. i'm currently developing a java application to log a website providing username ,password and captha code using htmlunit .
  2.  
  3. first i get webpage and take captha image out .it works perfectly .but the problem when i submit the form using following code the resulting page is html missed one .it because we have to give a time to load and execute javascript codes .but it i can't get resulting page even i give time to execute javascript .it looks like the resulting page doesn't wait .when i click submit html of result page came immediately but missing lot of html elements .
  4.  
  5. the solution seems to be
  6.  
  7. This is code part which take captha image .and this only work correctly after adding last `wait` line.otherwise i got html missing page
  8.  
  9. webClient = new WebClient();
  10. url = "http://evarsity.srmuniv.ac.in/srmswi/usermanager/youLogin.jsp";
  11. System.out.println("Loading page now: " + url);
  12. page = webClient.getPage(url);
  13. webClient.waitForBackgroundJavaScript(30 * 1000); /* will wait JavaScript to execute up to 30s */
  14.  
  15. now when i submit i don't know how to wait for result page without get result immediately .i used following code to submit form and added wait .but the waiting part not work.i get content missed hatml page .[this is html missed content plz look at it if needed][1]
  16.  
  17. HtmlForm form = page.getFormByName("frmStudentMain");
  18.  
  19. username = form.getInputByName("txtRegNumber");
  20. password = form.getInputByName("txtPwd");
  21. captha = form.getInputByName("txtverifycode");
  22.  
  23. username.setValueAttribute(uname.getText());
  24. username.setValueAttribute(upass.getText());
  25. captha.setValueAttribute(url);
  26. webClient.getCookieManager().setCookiesEnabled(true);
  27.  
  28. //final HtmlPage page2 = (HtmlPage) form.getInputByValue("Login").click();
  29. HtmlImage img = (HtmlImage) form.getByXPath("//img[ @onclick ='return submitData();']").get(0);
  30.  
  31. //webClient.waitForBackgroundJavaScript(1000*30);
  32. final HtmlPage page2 = (HtmlPage) img.click();
  33. webClient.waitForBackgroundJavaScript(1000*30);//something wrong here
  34.  
  35.  
  36. [1]: http://pastebin.com/Qv6FeyAn
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement