Guest User

Untitled

a guest
Jul 12th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.85 KB | None | 0 0
  1.  WebClient client = new WebClient(BrowserVersion.CHROME);
  2.         client.setHTMLParserListener(HTMLParserListener.LOG_REPORTER);
  3.         client.setJavaScriptEngine(new JavaScriptEngine(client));
  4.         client.getOptions().setJavaScriptEnabled(true);
  5.         client.getCookieManager().setCookiesEnabled(true);
  6.         client.getOptions().setThrowExceptionOnScriptError(false);
  7.         client.getOptions().setThrowExceptionOnFailingStatusCode(false);
  8.         client.setAjaxController(new NicelyResynchronizingAjaxController());
  9.         client.getCache().setMaxSize(0);
  10.         client.getOptions().setRedirectEnabled(true);
  11.  
  12.         String url = "https://accounts.google.com/login?hl=en#identifier";
  13.         HtmlPage loginPage = client.getPage(url);
  14.         client.waitForBackgroundJavaScript(1000000);
  15.  
  16.         HtmlForm loginForm = loginPage.getFirstByXPath("//form[@id='gaia_loginform']");
  17.         List<HtmlInput> buttonInputs = loginForm.getInputsByValue("signIn");
  18.         HtmlInput nextButton = Iterables.getFirst(buttonInputs, null);
  19.         HtmlInput loginButton = Iterables.getLast(buttonInputs);
  20.         Thread.sleep(2000);
  21.  
  22.         //setup email
  23.         HtmlInput emailInput = loginForm.getInputByName("Email");
  24.         emailInput.setValueAttribute(emailAddress);
  25.         Thread.sleep(2000);
  26.  
  27.         //click next button
  28.         nextButton.click();
  29.         client.waitForBackgroundJavaScript(1000000);
  30.         Thread.sleep(2000);
  31.  
  32.         //setup password
  33.         HtmlInput passwordInput = loginForm.getInputByName("Passwd");
  34.         passwordInput.setValueAttribute(password);
  35.  
  36.         //click login button
  37.         loginButton.click();
  38.         client.waitForBackgroundJavaScript(1000000);
  39.         Thread.sleep(2000);
  40.  
  41.         HtmlPage gmailPage = client.getPage("https://mail.google.com/mail/u/0/#inbox");
  42.         log.info(gmailPage.asText());
Advertisement
Add Comment
Please, Sign In to add comment