Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package stellar2;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.io.PrintWriter;
- import java.net.URL;
- import java.text.DateFormat;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import com.gargoylesoftware.htmlunit.BrowserVersion;
- import com.gargoylesoftware.htmlunit.ConfirmHandler;
- import com.gargoylesoftware.htmlunit.NiceRefreshHandler;
- import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
- import com.gargoylesoftware.htmlunit.Page;
- import com.gargoylesoftware.htmlunit.ScriptResult;
- import com.gargoylesoftware.htmlunit.WebClient;
- import com.gargoylesoftware.htmlunit.WebClientOptions;
- import com.gargoylesoftware.htmlunit.WebResponse;
- import com.gargoylesoftware.htmlunit.WebWindow;
- import com.gargoylesoftware.htmlunit.WebWindowListener;
- import com.gargoylesoftware.htmlunit.html.HtmlButtonInput;
- import com.gargoylesoftware.htmlunit.html.HtmlDivision;
- import com.gargoylesoftware.htmlunit.html.HtmlElement;
- import com.gargoylesoftware.htmlunit.html.HtmlForm;
- import com.gargoylesoftware.htmlunit.html.HtmlInput;
- import com.gargoylesoftware.htmlunit.html.HtmlOption;
- import com.gargoylesoftware.htmlunit.html.HtmlPage;
- import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
- import com.gargoylesoftware.htmlunit.html.HtmlSelect;
- import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
- import com.gargoylesoftware.htmlunit.html.HtmlTable;
- import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
- import org.apache.commons.io.FileUtils;
- @SuppressWarnings("unused")
- public class parseEmails {
- public static void main(String[] args) throws Exception {
- WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
- final HtmlPage page1 = webClient.getPage("http://mail.testing.com/");
- webClient.setRefreshHandler(new NiceRefreshHandler(5));
- webClient.getCookieManager().setCookiesEnabled(true);
- webClient.getOptions().setJavaScriptEnabled(true);
- webClient.getOptions().setActiveXNative(true);
- webClient.waitForBackgroundJavaScript(100);
- webClient.setAjaxController(new NicelyResynchronizingAjaxController());
- ConfirmHandler okHandler = new ConfirmHandler(){
- public boolean handleConfirm(Page page, String message) {
- return true;
- }
- };
- webClient.setConfirmHandler(okHandler);
- // Get the form that we are dealing with and within that form,
- // find the submit button and the field that we want to change.
- final HtmlForm form = page1.getFormByName("login");
- final HtmlDivision div = page1.getHtmlElementById("pnlLogin");
- //final HtmlTable table = page1.ge("table1");
- final HtmlSubmitInput button = form.getInputByName("btnLogin");
- final HtmlTextInput usernm = form.getInputByName("txtUsername");
- final HtmlPasswordInput passwrd = form.getInputByName("txtPassword");
- // Change the value of the text field
- usernm.setValueAttribute("khan@khan.net");
- passwrd.setValueAttribute("******");
- String htmlB =page1.asText();
- System.out.println(htmlB);
- // Now submit the form by clicking the button and get back the second page.
- final HtmlPage page2 = button.click();
- String htmlBody = page2.asXml();
- System.out.println(htmlBody);
- /* final HtmlForm form3 = page2.getFormByName("frmAddEditData");
- HtmlSelect select = (HtmlSelect)form3.getSelectByName("ReportType");
- HtmlOption option = select.getOptionByText("Invoice Data");
- select.setSelectedAttribute(option, true);
- final HtmlButtonInput btnGo = form3.getInputByName("btnGo");
- */
- webClient.closeAllWindows();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement