Created
November 22, 2009 16:16
-
-
Save jarib/240621 to your computer and use it in GitHub Desktop.
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 com.gargoylesoftware.htmlunit.WebClient; | |
import com.gargoylesoftware.htmlunit.html.HtmlPage; | |
import com.gargoylesoftware.htmlunit.html.HtmlElement; | |
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput; | |
public class FailingPasswordField { | |
public static void main(String[] args) throws Exception { | |
WebClient wc = new WebClient(); | |
HtmlPage page = wc.getPage("file:///tmp/form.html"); | |
HtmlPasswordInput passwordField = (HtmlPasswordInput)page.getElementById("form_password"); | |
passwordField.setValueAttribute(""); // clear the field before typing | |
for (char c : "mypassword".toCharArray()) { | |
passwordField.type(c); | |
} | |
System.out.println(passwordField.getAttribute("value")); | |
wc.closeAllWindows(); | |
} | |
} |
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
<h1>Form</h1> | |
<form action="/form" method="post"> | |
<p> | |
<label for="form_first_name">First Name</label> | |
<input type="text" name="form[first_name]" value="John" id="form_first_name"/> | |
</p> | |
<p> | |
<label for="form_last_name">Last Name</label> | |
<input type="text" name="form[last_name]" value="Smith" id="form_last_name"/> | |
</p> | |
<p> | |
<label for="form_password">Password</label> | |
<input type="password" name="form[password]" value="seeekrit" id="form_password"/> | |
</p> | |
<p> | |
<label for="form_image">Image</label> | |
<input type="file" name="form[image]" id="form_image"/> | |
</p> | |
<p> | |
<input type="hidden" name="form[token]" value="12345" id="form_token"/> | |
</p> | |
<p> | |
<label for="form_locale">Locale</label> | |
<select name="form[locale]" id="form_locale"> | |
<option value="sv">Swedish</option> | |
<option selected="selected" value="en">English</option> | |
<option value="fi">Finish</option> | |
<option value="no">Norwegian</option> | |
</select> | |
</p> | |
<p> | |
<label for="form_region">Region</label> | |
<select name="form[region]" id="form_region"> | |
<option>Sweden</option> | |
<option selected="selected">Norway</option> | |
<option>Finland</option> | |
</select> | |
</p> | |
<p> | |
<label for="form_city">City</label> | |
<select name="form[city]" id="form_city"> | |
<option>London</option> | |
<option>Stockholm</option> | |
<option>Paris</option> | |
</select> | |
</p> | |
<p> | |
<label for="form_tendency">Tendency</label> | |
<select name="form[tendency]" id="form_tendency"></select> | |
</p> | |
<p> | |
<label for="form_description">Description</label></br> | |
<textarea name="form[description]" id="form_description">Descriptive text goes here</textarea> | |
<p> | |
<p> | |
<input type="radio" name="form[gender]" value="male" id="gender_male"/> | |
<label for="gender_male">Male</label> | |
<input type="radio" name="form[gender]" value="female" id="gender_female" checked="checked"/> | |
<label for="gender_female">Female</label> | |
<input type="radio" name="form[gender]" value="both" id="gender_both"/> | |
<label for="gender_both">Both</label> | |
</p> | |
<p> | |
<input type="checkbox" value="dog" name="form[pets][]" id="form_pets_dog" checked="checked"/> | |
<label for="form_pets_dog">Dog</label> | |
<input type="checkbox" value="cat" name="form[pets][]" id="form_pets_cat"/> | |
<label for="form_pets_cat">Cat</label> | |
<input type="checkbox" value="hamster" name="form[pets][]" id="form_pets_hamster" checked="checked"/> | |
<label for="form_pets_hamster">Hamster</label> | |
</p> | |
<p> | |
<input type="submit" name="form[awesome]" id="awe123" value="awesome"/> | |
<input type="submit" name="form[crappy]" id="crap321" value="crappy"/> | |
<input type="image" name="form[okay]" id="okay556" value="okay"/> | |
</p> | |
</form> | |
<form action="/form/get?foo=bar" method="get"> | |
<p> | |
<label for="form_middle_name">Middle Name</label> | |
<input type="text" name="form[middle_name]" value="Darren" id="form_middle_name"/> | |
</p> | |
<p> | |
<input type="submit" name="form[mediocre]" id="mediocre" value="med"/> | |
<p> | |
</form> | |
<form action="/upload" method="post" enctype="multipart/form-data"> | |
<p> | |
<label for="form_document">Document</label> | |
<input type="file" name="form[document]" id="form_document"/> | |
</p> | |
<p> | |
<input type="submit" value="Upload"/> | |
<p> | |
</form> | |
<form action="/redirect" method="post"> | |
<p> | |
<input type="submit" value="Go FAR"/> | |
</p> | |
</form> |
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
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 8 | |
at java.lang.String.substring(String.java:1934) | |
at com.gargoylesoftware.htmlunit.html.DoTypeProcessor.doType(DoTypeProcessor.java:40) | |
at com.gargoylesoftware.htmlunit.html.HtmlPasswordInput.doType(HtmlPasswordInput.java:130) | |
at com.gargoylesoftware.htmlunit.html.HtmlElement.type(HtmlElement.java:477) | |
at com.gargoylesoftware.htmlunit.html.HtmlElement.type(HtmlElement.java:444) | |
at FailingPasswordField.main(FailingPasswordField.java:19) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment