JSoup is used to parse the following html
<input type="checkbox" id="id12" name="renewalCheckboxGroup" value="check1" class="wicket-id11" />
Here is the code of JSoup
Document document = Jsoup.parse("<input type=\"checkbox\" id=\"id12\" name=\"renewalCheckboxGroup\" value=\"check1\" class=\"wicket-id11\" />");
System.out.println(document.id());
Expected result should be id12, however, the returned id is an empty string. I also try to call attribute("id") function as well, but still in vain. How to solve it? Thank YOu
As far as I know you should select/find/extract your desired Element from your document and only then access its attribute (id for example)
You got several options:
Elements inputs = document.getElementsByTag("input"); //then access the one at 0 index
or
Element input = doc.getElementById("id12");
or
Elements inputs = doc.select("input[name=renewalCheckboxGroup]"); //then access the one at 0 index
take a look at the docs for more options...
Use selector-syntax to find elements
Use DOM methods to navigate a document
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With