I am currently using HTMLunit to enter a site with a validation and redirect page. Some of my codes for this:
//---------------------------------Login Page--------------------------------- HtmlPage PageLogin = webClient.getPage(url); HtmlElement submitButton = (HtmlElement) PageLogin.getByXPath(Xpath To Button).get(0); HtmlTextInput name = (HtmlTextInput) PageLogin.getElementById("UserIdInput"); HtmlPasswordInput pass = (HtmlPasswordInput)PageLogin.getElementById("ADloginPasswordInput"); name.setText(username); pass.setText(password); System.out.println("Logging in to site"); //------------------------------------------------------------------------ //---------------------------------Pass varified Page---------------------- HtmlPage pagePassVarified = submitButton.click(); System.out.println("Successfully Logged in to site"); HtmlElement btnContinue = (HtmlElement) pagePassVarified.getElementById("BtnClickToContinue"); //--------------------------------------------------------- //---------------------Home Page---------------------------------- HtmlPage pageHome = btnContinue.click(); System.out.println("Home Page accessed"); //----------------------------------------------------------------
This code goes to the login page, adds the username and passwords to the text fields and presses the submit button. Then we are redirected to the page โWait 5 seconds or click here to go to the main pageโ, where the โContinueโ button is clicked. Finally, we come to our homepage, which we wanted to enter. I selected the page elements of both ID and Xpath when the identifier was not available.
source share