Advertisement
Guest User

HTML

a guest
Jul 23rd, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. package stellar2;
  2.  
  3. import java.io.File;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.io.OutputStream;
  8. import java.io.PrintWriter;
  9. import java.net.URL;
  10. import java.text.DateFormat;
  11. import java.text.SimpleDateFormat;
  12. import java.util.Calendar;
  13.  
  14. import com.gargoylesoftware.htmlunit.BrowserVersion;
  15. import com.gargoylesoftware.htmlunit.ConfirmHandler;
  16. import com.gargoylesoftware.htmlunit.NiceRefreshHandler;
  17. import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
  18. import com.gargoylesoftware.htmlunit.Page;
  19. import com.gargoylesoftware.htmlunit.ScriptResult;
  20. import com.gargoylesoftware.htmlunit.WebClient;
  21. import com.gargoylesoftware.htmlunit.WebClientOptions;
  22. import com.gargoylesoftware.htmlunit.WebResponse;
  23. import com.gargoylesoftware.htmlunit.WebWindow;
  24. import com.gargoylesoftware.htmlunit.WebWindowListener;
  25. import com.gargoylesoftware.htmlunit.html.HtmlButtonInput;
  26. import com.gargoylesoftware.htmlunit.html.HtmlDivision;
  27. import com.gargoylesoftware.htmlunit.html.HtmlElement;
  28. import com.gargoylesoftware.htmlunit.html.HtmlForm;
  29. import com.gargoylesoftware.htmlunit.html.HtmlInput;
  30. import com.gargoylesoftware.htmlunit.html.HtmlOption;
  31. import com.gargoylesoftware.htmlunit.html.HtmlPage;
  32. import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
  33. import com.gargoylesoftware.htmlunit.html.HtmlSelect;
  34. import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
  35. import com.gargoylesoftware.htmlunit.html.HtmlTable;
  36. import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. import org.apache.commons.io.FileUtils;
  48.  
  49. @SuppressWarnings("unused")
  50.  
  51.  
  52. public class parseEmails {
  53. public static void main(String[] args) throws Exception {
  54.  
  55. WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
  56.  
  57.  
  58. final HtmlPage page1 = webClient.getPage("http://mail.testing.com/");
  59. webClient.setRefreshHandler(new NiceRefreshHandler(5));
  60. webClient.getCookieManager().setCookiesEnabled(true);
  61. webClient.getOptions().setJavaScriptEnabled(true);
  62. webClient.getOptions().setActiveXNative(true);
  63. webClient.waitForBackgroundJavaScript(100);
  64. webClient.setAjaxController(new NicelyResynchronizingAjaxController());
  65.  
  66.  
  67.  
  68. ConfirmHandler okHandler = new ConfirmHandler(){
  69. public boolean handleConfirm(Page page, String message) {
  70. return true;
  71. }
  72. };
  73.  
  74. webClient.setConfirmHandler(okHandler);
  75.  
  76.  
  77.  
  78. // Get the form that we are dealing with and within that form,
  79. // find the submit button and the field that we want to change.
  80. final HtmlForm form = page1.getFormByName("login");
  81. final HtmlDivision div = page1.getHtmlElementById("pnlLogin");
  82. //final HtmlTable table = page1.ge("table1");
  83. final HtmlSubmitInput button = form.getInputByName("btnLogin");
  84. final HtmlTextInput usernm = form.getInputByName("txtUsername");
  85. final HtmlPasswordInput passwrd = form.getInputByName("txtPassword");
  86.  
  87. // Change the value of the text field
  88. usernm.setValueAttribute("khan@khan.net");
  89. passwrd.setValueAttribute("******");
  90. String htmlB =page1.asText();
  91. System.out.println(htmlB);
  92.  
  93. // Now submit the form by clicking the button and get back the second page.
  94. final HtmlPage page2 = button.click();
  95. String htmlBody = page2.asXml();
  96.  
  97.  
  98. System.out.println(htmlBody);
  99.  
  100.  
  101.  
  102.  
  103.  
  104. /* final HtmlForm form3 = page2.getFormByName("frmAddEditData");
  105. HtmlSelect select = (HtmlSelect)form3.getSelectByName("ReportType");
  106. HtmlOption option = select.getOptionByText("Invoice Data");
  107. select.setSelectedAttribute(option, true);
  108.  
  109. final HtmlButtonInput btnGo = form3.getInputByName("btnGo");
  110.  
  111.  
  112. */
  113. webClient.closeAllWindows();
  114.  
  115. }
  116.  
  117.  
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement