WebClient client = new WebClient(); HtmlPage page = client.getPage("http://stackoverflow.com"); // create a submit button - it doesn't work with 'input' HtmlElement button = page.createElement("button"); button.setAttribute("type", "submit"); // append the button to the form HtmlElement form = ...; form.appendChild(button); // submit the form page = button.click();
HtmlElement fakeButton = page.createElement("button"); button.setAttribute("type", "submit"); // add the button to the form form.appendChild(fakeButton ); fakeButton.click();
/** * Simulates clicking on this element, returning the page in the window that has the focus * after the element has been clicked. Note that the returned page may or may not be the same * as the original page, depending on the type of element being clicked, the presence of JavaScript * action listeners, etc. * * @param <P> the page type * @return the page that occupies this element's window after the element has been clicked * @exception IOException if an IO error occurs */ @SuppressWarnings("unchecked") public <P extends Page> P click() throws IOException { return (P) click(false, false, false); }
/** * Simulates clicking on this element, returning the page in the window that has the focus * after the element has been clicked. Note that the returned page may or may not be the same * as the original page, depending on the type of element being clicked, the presence of JavaScript * action listeners, etc. * * @param <P> the page type * @return the page that occupies this element's window after the element has been clicked * @exception IOException if an IO error occurs */ @SuppressWarnings("unchecked") public <P extends Page> P click() throws IOException { return (P) click(false, false, false); }
/** * Simulates clicking on this element, returning the page in the window that has the focus * after the element has been clicked. Note that the returned page may or may not be the same * as the original page, depending on the type of element being clicked, the presence of JavaScript * action listeners, etc. * * @param <P> the page type * @return the page that occupies this element's window after the element has been clicked * @exception IOException if an IO error occurs */ @SuppressWarnings("unchecked") public <P extends Page> P click() throws IOException { return (P) click(false, false, false); }
HtmlElement a = reCaptchaFrame.querySelector("recaptcha-checkbox-checkmark"); a.click();
/** * Click the component needed to submit the form. * * @param page The page where credentials are entered. * @return The resulting Page * @throws java.io.IOException If the form can not be submitted. */ protected Page clickSubmitComponent(HtmlPage page) throws IOException { HtmlElement htmlElement = getElement(page, this.submitComponent); return htmlElement.click(); }
/** * Click this element. This simulates the action of the user clicking with the mouse. * @throws IOException if this click triggers a page load that encounters problems */ public void jsxFunction_click() throws IOException { getDomNodeOrDie().click(); }
/** * Click this element. This simulates the action of the user clicking with the mouse. * @throws IOException if this click triggers a page load that encounters problems */ public void jsxFunction_click() throws IOException { getDomNodeOrDie().click(); }
/** * Click this element. This simulates the action of the user clicking with the mouse. * @throws IOException if this click triggers a page load that encounters problems */ public void jsxFunction_click() throws IOException { getDomNodeOrDie().click(); }
HtmlPage page1 = webClient.getPage("myURI"); HtmlElement htmlElement = (HtmlElement) page1.getByXPath("loginHiddenButtonXPATH").get(0); webClient.setJavaScriptEnabled(false); page1 = htmlElement.click(); webClient.setJavaScriptEnabled(true);
@Override public void clickElementByXPath(String xpath) { HtmlElement e = getHtmlElementByXPath(xpath); if (e == null) { throw new RuntimeException("No element found with xpath \"" + xpath + "\""); } try { e.click(); } catch (IOException exp) { throw new RuntimeException("Click failed", exp); } }
HtmlElement ele=page.createElement("input"); ele.setAttribute("type","submit"); form.appendChild(ele); ele.click();
/** * Click the indicated button (input type=button). * * @param buttonId */ @Override public void clickButton(String buttonId) { HtmlElement btn = getButton(buttonId); try { btn.click(); } catch (Exception e) { throw new RuntimeException(e); } }
HtmlForm form = page.getForms().get(0); HtmlElement input = form.getElementsByAttribute("input", "name", "vote").get(0); page = input.click();
public void clickElementWithId(String id) { HtmlElement element = (HtmlElement)currentPage.getElementById(id); checkState(element != null, "Cannot find element: " + id); try { element.click(); waitForAsyncEventsThatBeginWithinDefaultTime(); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Click this element. This simulates the action of the user clicking with the mouse. * @throws IOException if this click triggers a page load that encounters problems */ @JsxFunction public void click() throws IOException { // when triggered from js the visibility is ignored getDomNodeOrDie().click(false, false, false, true, true, false); }
/** * Click this element. This simulates the action of the user clicking with the mouse. * @throws IOException if this click triggers a page load that encounters problems */ @JsxFunction public void click() throws IOException { // when triggered from js the visibility is ignored getDomNodeOrDie().click(false, false, false, true, true, false); }
final HtmlPage page = webClient.getPage("http://www.google.com"); HtmlElement inputField = page.getElementByName("q"); inputField.type("Example input"); HtmlElement btnG = page.getElementByName("btnG"); Page secondPage = btnG.click(); if (secondPage instanceof HtmlPage) { System.out.println(page.getTitleText()); System.out.println(((HtmlPage)secondPage).getTitleText()); }
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()); }