I need to parse HTML elements from a webpage in Java, fill out a form and submit it to simulate a login.
I've been doing a little bit of research and here's what I did using the jsoup
library.
However, after implementing this, I realized jsoup
is only for parsing and can't perform button click, for example.
In this example, I need to perform a click on submitButton
element.
try {
Document htmlDoc = Jsoup.connect(MY_URL).get();
Element loginForm = htmlDoc.getElementById("login-form");
Element usernameField = loginForm.getElementById("username");
Element passwordField = loginForm.getElementById("passwd");
Element submitButton = loginForm.getElementById("submit");
usernameField.val(username);
passwordField.val(password);
// I need to simulate `submitButton` click so I can login
} catch (Exception e) {
Log.e("TAG", e.toString());
}
Am I correct in my understanding that jsoup
is not capable of doing this?
If so, is there a library for Android that can?
I understand there are many Java libraries but most can't work with Android (ex. HtmlUtil) due to javax
limitation.