I want to scrape some information in a website that requires me to login.
I've come across HtmlUnit and I'm already able to locate the login form, fill the email and passwords inputs. The problem I have is I cannot submit this form because there isn't a submit button.
I already tried creating a temporary button and it didn't work. Followed this question.
Tried locating the submit input as an Anchor, executing java script, etc, to no avail.
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_52);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setCssEnabled(false);
webClient.setAjaxController(new NicelyResynchronizingAjaxController());
webClient.getOptions().setRedirectEnabled(true);
// disable caching
webClient.getCache().setMaxSize(0);
// Get the first page
final HtmlPage page = webClient.getPage("https://www.jpdi.pt");
webClient.waitForBackgroundJavaScript(10000);
final HtmlForm form = page.getHtmlElementById("login_form");
form.getInputByName("login_email").setValueAttribute("my_email");
HtmlInput passWordInput = form.getInputByName("login_password");
passWordInput.setValueAttribute("my_password");
//wait a little
Thread.sleep(2000);
ScriptResult result= page.executeJavaScript("document.getElementById('submit_login').click()");
final HtmlPage secondPage = (HtmlPage) page.getWebClient().getCurrentWindow().getEnclosedPage();
System.out.println(secondPage.asText());
The page that is printed is the original with the two inputs filled and not the page I'm expecting.. Any ideas?