try (final WebClient webClient = new WebClient(BrowserVersion.CHROME)) { // Get the first page final HtmlPage page1 = webClient.getPage("http://www.homedepot.ca"); // Get the form that we are dealing with and within that form, // find the submit button and the field that we want to change. final HtmlForm form = page1.getFormByName("search_terms_form"); final HtmlElement button = form.getFirstByXPath("//button[@class='search-button']"); final HtmlTextInput textField = form.getInputByName("q"); // Change the value of the text field textField.setValueAttribute("drill"); // Now submit the form by clicking the button button.click(); System.out.println(page1.getTitleText()); }
//Get Page HtmlPage page1 = webClient.getPage("https://login-url/"); //Wait for background Javascript webClient.waitForBackgroundJavaScript(10000); //Get first form on page HtmlForm form = page1.getForms().get(0); //Get login input fields using input field name HtmlTextInput userName = form.getInputByName("UserName"); HtmlPasswordInput password = form.getInputByName("Password"); //Set input values userName.setValueAttribute("MyUserName"); password.setValueAttribute("MyPassword"); //Find the first button in form using name, id or xpath HtmlElement button = (HtmlElement) form.getFirstByXPath("//button"); //Post by clicking the button and cast the result, login arrival url, to a new page and repeat what you did with page1 or something else :) HtmlPage page2 = (HtmlPage) button.click(); //Profit System.out.println(page2.asXml());
if (form != null && c == '\n' && isSubmittableByEnter()) { if (!ie) { final HtmlSubmitInput submit = form.getFirstByXPath(".//input[@type='submit']"); if (submit != null) { return submit.click();
if (form != null && c == '\n' && isSubmittableByEnter()) { if (!ie) { final HtmlSubmitInput submit = form.getFirstByXPath(".//input[@type='submit']"); if (submit != null) { return submit.click();
if (form != null && c == '\n' && isSubmittableByEnter()) { if (!ie) { final HtmlSubmitInput submit = form.getFirstByXPath(".//input[@type='submit']"); if (submit != null) { return submit.click();
final HtmlSubmitInput submit = form.getFirstByXPath(".//input[@type='submit']"); if (submit != null) { return submit.click();
final HtmlSubmitInput submit = form.getFirstByXPath(".//input[@type='submit']"); if (submit != null) { return submit.click();