@Test public void actionWithNoBaseUri() { String html = "<form><input name='q'></form>"; Document doc = Jsoup.parse(html); FormElement form = ((FormElement) doc.select("form").first()); boolean threw = false; try { Connection con = form.submit(); } catch (IllegalArgumentException e) { threw = true; assertEquals("Could not determine a form action URL for submit. Ensure you set a base URI when parsing.", e.getMessage()); } assertTrue(threw); }
public Connection submit() { String action = hasAttr("action") ? absUrl("action") : baseUri(); Validate.notEmpty(action, "Could not determine a form action URL for submit. Ensure you set a base URI when parsing."); Connection.Method method = attr("method").toUpperCase().equals("POST") ? Connection.Method.POST : Connection.Method.GET; return Jsoup.connect(action) .data(formData()) .method(method); }
FormElement extends Element { public Connection submit() { String action = hasAttr("action") ? absUrl("action") : baseUri(); Validate.notEmpty(action, "Could not determine a form action URL for submit. Ensure you set a base URI when parsing."); Connection.Method method = attr("method").toUpperCase().equals("POST") ? Connection.Method.POST : Connection.Method.GET; return Jsoup.connect(action) .data(formData()) .method(method); } }
FormElement extends Element { public Connection submit() { String action = hasAttr("action") ? absUrl("action") : baseUri(); Validate.notEmpty(action, "Could not determine a form action URL for submit. Ensure you set a base URI when parsing."); Connection.Method method = attr("method").toUpperCase().equals("POST") ? Connection.Method.POST : Connection.Method.GET; return Jsoup.connect(action) .data(formData()) .method(method); } FormElement(Tag tag, String baseUri, Attributes attributes); }
FormElement extends Element { public Connection submit() { String action = hasAttr("action") ? absUrl("action") : baseUri(); Validate.notEmpty(action, "Could not determine a form action URL for submit. Ensure you set a base URI when parsing."); Connection.Method method = attr("method").toUpperCase().equals("POST") ? Connection.Method.POST : Connection.Method.GET; return Jsoup.connect(action) .data(formData()) .method(method); } FormElement(Tag tag, String baseUri, Attributes attributes); Elements elements(); FormElement addElement(Element element); Connection submit(); List<Connection.KeyVal> formData(); }
FormElement extends Element { public Connection submit() { String action = hasAttr("action") ? absUrl("action") : baseUri(); Validate.notEmpty(action, "Could not determine a form action URL for submit. Ensure you set a base URI when parsing."); Connection.Method method = attr("method").toUpperCase().equals("POST") ? Connection.Method.POST : Connection.Method.GET; return Jsoup.connect(action) .data(formData()) .method(method); } FormElement(Tag tag, String baseUri, Attributes attributes); Elements elements(); FormElement addElement(Element element); Connection submit(); List<Connection.KeyVal> formData();  }