Advertisement
Guest User

Untitled

a guest
Jan 5th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. public static void main(String args[]) throws Exception {
  2. login();
  3. }
  4.  
  5. @SuppressWarnings("resource")
  6. public static void login() throws Exception {
  7.  
  8. // Open the webclient using Internet Explorer (Chrome does not work).
  9. final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER);
  10. // Get the first page
  11. final HtmlPage page = webClient.getPage("http://telephone.qqest.com/phone/Login/Login.asp");
  12. // Get the form that we are dealing with.
  13. final HtmlForm loginForm = page.getFormByName("frmLogin");
  14. final HtmlTextInput userName = loginForm.getInputByName("Login");
  15. final com.gargoylesoftware.htmlunit.html.HtmlPasswordInput passWord = (com.gargoylesoftware.htmlunit.html.HtmlPasswordInput)
  16. loginForm.getInputByName("Password");
  17. final HtmlTextInput companyID = loginForm.getInputByName("Ident");
  18.  
  19. webClient.getOptions().setCssEnabled(false);
  20. webClient.getOptions().setRedirectEnabled(true);
  21. webClient.setAjaxController(new NicelyResynchronizingAjaxController());
  22. webClient.getCookieManager().setCookiesEnabled(true);
  23. //final HtmlInput login = loginForm.getInputByName("Login");
  24.  
  25. // Change the values of the text fields.
  26. userName.setValueAttribute("xxxx");
  27. passWord.setValueAttribute("xxxxx");
  28. companyID.setValueAttribute("xxxxx");
  29.  
  30. //create a submit button - it doesn't work with 'input'
  31. DomElement loginBtn = page.createElement("button");
  32. loginBtn.setAttribute("type", "submit");
  33. // append the button to the form
  34. loginForm.appendChild(loginBtn);
  35. // submit the form
  36. loginBtn.click();
  37.  
  38. //navigate to page for import.
  39. HtmlPage page3 = webClient.getPage("http://telephone.qqest.com/phone/Imports/Employee/Module.asp");
  40. //populate the textfield with the specified file.
  41. final HtmlForm importForm = page3.getFormByName("ImportForm");
  42. final HtmlFileInput inputFile = importForm.getInputByName("UploadFile");
  43. inputFile.setValueAttribute("C:\Users\thisFile.xls");
  44. inputFile.click();
  45. final HtmlSubmitInput importBtn = (HtmlSubmitInput)importForm.getInputByValue("Import");
  46.  
  47. try {
  48. importBtn.fireEvent(Event.TYPE_INPUT);
  49. }
  50. catch (NullPointerException ex) {
  51. System.err.println(ex);
  52. }
  53.  
  54. HtmlPage page4 = webClient.getPage("http://telephone.qqest.com/phone/Imports/Employee/ImportFile.asp?FileType=application/vnd.ms-excel&FilePath=c%3A%5Cinetpub%5Cwwwroot%5Cphone%5CDownloads%5CImports%5C&FileName=thisFile.xls.asp");
  55.  
  56. System.out.println("Import Page: " + page4.asText());
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement