Skip to content

Instantly share code, notes, and snippets.

@apaci
Created June 2, 2012 01:13
Show Gist options
  • Save apaci/2856044 to your computer and use it in GitHub Desktop.
Save apaci/2856044 to your computer and use it in GitHub Desktop.
HTMLUnit Thingy -2
import java.io.IOException;
import java.net.MalformedURLException;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlHiddenInput;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
public class cza {
public static void main(String[] args) throws FailingHttpStatusCodeException, MalformedURLException, IOException {
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_3_6);
webClient.setThrowExceptionOnScriptError(false);
webClient.setJavaScriptEnabled(false);
String address = "djkashdah.com";
HtmlPage currentPage = webClient.getPage(address);
final HtmlForm form = currentPage.getFirstByXPath("//form[@action='/login']");
HtmlTextInput username = (HtmlTextInput) currentPage.getElementById("login_email");
HtmlPasswordInput password = (HtmlPasswordInput) currentPage.getElementById("login_password");
username.setText("dasdsadas");
password.setText("dasdsada");
HtmlSubmitInput firstButton = (HtmlSubmitInput) currentPage.getElementById("login_submit");
//System.out.print(firstButton.asText());
HtmlPage newPage = firstButton.click();
//System.out.println(newPage.asText());
//System.out.println("***button test start***");
///////////// problems start after this line
HtmlForm form2 = newPage.getFirstByXPath("//form[@action='authorize']");
System.out.println(form2.asText());
//
//form2.getInputByName("allow_access");
//HtmlPage finalPage = form2.getButtonByName("allow_access").click();
//HtmlPage finalPage = form2.getInputByName("allow_access").click();
//HtmlPage finalPage = form2.getInputByValue("Allow").click();
//HtmlPage finalPage = newPage.getElementByName("Allow").click();
//HtmlButton button1 = (HtmlButton) newPage.getElementByName("allow_access");
//System.out.println(button1.asText());
//HtmlSubmitInput input1 = form2.getInputByName("allow_access");
//System.out.print(input1.asText());
//HtmlButton button = newPage.getElementByName("allow_access");
//HtmlPage page = button.click() ;
///////
//System.out.println(finalPage.asText());
System.out.println("***button test end***");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment