Created
June 1, 2012 17:41
-
-
Save apaci/2853917 to your computer and use it in GitHub Desktop.
HTMLUnit Thingy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.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); | |
String address = "https://www.com:1234/1/var?blabla=blabla&var2=blablabla"; | |
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("username@username.com"); | |
password.setText("password"); | |
HtmlSubmitInput firstButton = (HtmlSubmitInput) currentPage.getElementById("login_submit"); | |
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']"); | |
// | |
//form2.getInputByName("allow"); | |
HtmlPage finalPage = form2.getButtonByName("allow").click(); | |
// | |
//HtmlButton button = newPage.getElementByName("allow"); | |
//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
These also fail: