org.jsoup.nodes.FormElement Java Examples

The following examples show how to use org.jsoup.nodes.FormElement. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: astor   Author: SpoonLabs   File: UrlConnectTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test fetching a form, and submitting it with a file attached.
 */
@Test
public void postHtmlFile() throws IOException {
    Document index = Jsoup.connect("http://direct.infohound.net/tidy/").get();
    FormElement form = index.select("[name=tidy]").forms().get(0);
    Connection post = form.submit();

    File uploadFile = ParseTest.getFile("/htmltests/google-ipod.html");
    FileInputStream stream = new FileInputStream(uploadFile);
    
    Connection.KeyVal fileData = post.data("_file");
    fileData.value("check.html");
    fileData.inputStream(stream);

    Connection.Response res;
    try {
        res = post.execute();
    } finally {
        stream.close();
    }

    Document out = res.parse();
    assertTrue(out.text().contains("HTML Tidy Complete"));
}
 
Example #2
Source Project: astor   Author: SpoonLabs   File: UrlConnectTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test fetching a form, and submitting it with a file attached.
 */
@Test
public void postHtmlFile() throws IOException {
    Document index = Jsoup.connect("http://direct.infohound.net/tidy/").get();
    FormElement form = index.select("[name=tidy]").forms().get(0);
    Connection post = form.submit();

    File uploadFile = ParseTest.getFile("/htmltests/google-ipod.html");
    FileInputStream stream = new FileInputStream(uploadFile);
    
    Connection.KeyVal fileData = post.data("_file");
    fileData.value("check.html");
    fileData.inputStream(stream);

    Connection.Response res;
    try {
        res = post.execute();
    } finally {
        stream.close();
    }

    Document out = res.parse();
    assertTrue(out.text().contains("HTML Tidy Complete"));
}
 
Example #3
Source Project: astor   Author: SpoonLabs   File: UrlConnectTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test fetching a form, and submitting it with a file attached.
 */
@Test
public void postHtmlFile() throws IOException {
    Document index = Jsoup.connect("http://direct.infohound.net/tidy/").get();
    FormElement form = index.select("[name=tidy]").forms().get(0);
    Connection post = form.submit();

    File uploadFile = ParseTest.getFile("/htmltests/google-ipod.html");
    FileInputStream stream = new FileInputStream(uploadFile);
    
    Connection.KeyVal fileData = post.data("_file");
    fileData.value("check.html");
    fileData.inputStream(stream);

    Connection.Response res;
    try {
        res = post.execute();
    } finally {
        stream.close();
    }

    Document out = res.parse();
    assertTrue(out.text().contains("HTML Tidy Complete"));
}
 
Example #4
Source Project: astor   Author: SpoonLabs   File: HtmlTreeBuilder.java    License: GNU General Public License v2.0 5 votes vote down vote up
FormElement insertForm(Token.StartTag startTag, boolean onStack) {
    Tag tag = Tag.valueOf(startTag.name(), settings);
    FormElement el = new FormElement(tag, baseUri, startTag.attributes);
    setFormElement(el);
    insertNode(el);
    if (onStack)
        stack.add(el);
    return el;
}
 
Example #5
Source Project: astor   Author: SpoonLabs   File: HtmlParserTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test public void createsFormElements() {
    String html = "<body><form><input id=1><input id=2></form></body>";
    Document doc = Jsoup.parse(html);
    Element el = doc.select("form").first();

    assertTrue("Is form element", el instanceof FormElement);
    FormElement form = (FormElement) el;
    Elements controls = form.elements();
    assertEquals(2, controls.size());
    assertEquals("1", controls.get(0).id());
    assertEquals("2", controls.get(1).id());
}
 
Example #6
Source Project: astor   Author: SpoonLabs   File: HtmlParserTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test public void associatedFormControlsWithDisjointForms() {
    // form gets closed, isn't parent of controls
    String html = "<table><tr><form><input type=hidden id=1><td><input type=text id=2></td><tr></table>";
    Document doc = Jsoup.parse(html);
    Element el = doc.select("form").first();

    assertTrue("Is form element", el instanceof FormElement);
    FormElement form = (FormElement) el;
    Elements controls = form.elements();
    assertEquals(2, controls.size());
    assertEquals("1", controls.get(0).id());
    assertEquals("2", controls.get(1).id());

    assertEquals("<table><tbody><tr><form></form><input type=\"hidden\" id=\"1\"><td><input type=\"text\" id=\"2\"></td></tr><tr></tr></tbody></table>", TextUtil.stripNewlines(doc.body().html()));
}
 
Example #7
Source Project: astor   Author: SpoonLabs   File: HtmlTreeBuilder.java    License: GNU General Public License v2.0 5 votes vote down vote up
FormElement insertForm(Token.StartTag startTag, boolean onStack) {
    Tag tag = Tag.valueOf(startTag.name(), settings);
    FormElement el = new FormElement(tag, baseUri, startTag.attributes);
    setFormElement(el);
    insertNode(el);
    if (onStack)
        stack.add(el);
    return el;
}
 
Example #8
Source Project: astor   Author: SpoonLabs   File: HtmlParserTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test public void createsFormElements() {
    String html = "<body><form><input id=1><input id=2></form></body>";
    Document doc = Jsoup.parse(html);
    Element el = doc.select("form").first();

    assertTrue("Is form element", el instanceof FormElement);
    FormElement form = (FormElement) el;
    Elements controls = form.elements();
    assertEquals(2, controls.size());
    assertEquals("1", controls.get(0).id());
    assertEquals("2", controls.get(1).id());
}
 
Example #9
Source Project: astor   Author: SpoonLabs   File: HtmlParserTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Test public void associatedFormControlsWithDisjointForms() {
    // form gets closed, isn't parent of controls
    String html = "<table><tr><form><input type=hidden id=1><td><input type=text id=2></td><tr></table>";
    Document doc = Jsoup.parse(html);
    Element el = doc.select("form").first();

    assertTrue("Is form element", el instanceof FormElement);
    FormElement form = (FormElement) el;
    Elements controls = form.elements();
    assertEquals(2, controls.size());
    assertEquals("1", controls.get(0).id());
    assertEquals("2", controls.get(1).id());

    assertEquals("<table><tbody><tr><form></form><input type=\"hidden\" id=\"1\"><td><input type=\"text\" id=\"2\"></td></tr><tr></tr></tbody></table>", TextUtil.stripNewlines(doc.body().html()));
}
 
Example #10
Source Project: astor   Author: SpoonLabs   File: HtmlTreeBuilder.java    License: GNU General Public License v2.0 4 votes vote down vote up
FormElement getFormElement() {
    return formElement;
}
 
Example #11
Source Project: astor   Author: SpoonLabs   File: HtmlTreeBuilder.java    License: GNU General Public License v2.0 4 votes vote down vote up
void setFormElement(FormElement formElement) {
    this.formElement = formElement;
}
 
Example #12
Source Project: astor   Author: SpoonLabs   File: HtmlTreeBuilder.java    License: GNU General Public License v2.0 4 votes vote down vote up
FormElement getFormElement() {
    return formElement;
}
 
Example #13
Source Project: astor   Author: SpoonLabs   File: HtmlTreeBuilder.java    License: GNU General Public License v2.0 4 votes vote down vote up
void setFormElement(FormElement formElement) {
    this.formElement = formElement;
}