Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String args[]) throws Exception {
- login();
- }
- @SuppressWarnings("resource")
- public static void login() throws Exception {
- // Open the webclient using Internet Explorer (Chrome does not work).
- final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER);
- // Get the first page
- final HtmlPage page = webClient.getPage("http://telephone.qqest.com/phone/Login/Login.asp");
- // Get the form that we are dealing with.
- final HtmlForm loginForm = page.getFormByName("frmLogin");
- final HtmlTextInput userName = loginForm.getInputByName("Login");
- final com.gargoylesoftware.htmlunit.html.HtmlPasswordInput passWord = (com.gargoylesoftware.htmlunit.html.HtmlPasswordInput)
- loginForm.getInputByName("Password");
- final HtmlTextInput companyID = loginForm.getInputByName("Ident");
- webClient.getOptions().setCssEnabled(false);
- webClient.getOptions().setRedirectEnabled(true);
- webClient.setAjaxController(new NicelyResynchronizingAjaxController());
- webClient.getCookieManager().setCookiesEnabled(true);
- //final HtmlInput login = loginForm.getInputByName("Login");
- // Change the values of the text fields.
- userName.setValueAttribute("xxxx");
- passWord.setValueAttribute("xxxxx");
- companyID.setValueAttribute("xxxxx");
- //create a submit button - it doesn't work with 'input'
- DomElement loginBtn = page.createElement("button");
- loginBtn.setAttribute("type", "submit");
- // append the button to the form
- loginForm.appendChild(loginBtn);
- // submit the form
- loginBtn.click();
- //navigate to page for import.
- HtmlPage page3 = webClient.getPage("http://telephone.qqest.com/phone/Imports/Employee/Module.asp");
- //populate the textfield with the specified file.
- final HtmlForm importForm = page3.getFormByName("ImportForm");
- final HtmlFileInput inputFile = importForm.getInputByName("UploadFile");
- inputFile.setValueAttribute("C:\Users\thisFile.xls");
- inputFile.click();
- final HtmlSubmitInput importBtn = (HtmlSubmitInput)importForm.getInputByValue("Import");
- try {
- importBtn.fireEvent(Event.TYPE_INPUT);
- }
- catch (NullPointerException ex) {
- System.err.println(ex);
- }
- 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");
- System.out.println("Import Page: " + page4.asText());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement