@Test public void submittingForm() throws Exception { final WebClient webClient = new WebClient(); // Get the first page final HtmlPage page1 = webClient.getPage("http://some_url"); // 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("myform"); final HtmlSubmitInput button = form.getInputByName("submitbutton"); final HtmlTextInput textField = form.getInputByName("userid"); // Change the value of the text field textField.setValueAttribute("root"); // Now submit the form by clicking the button and get back the second page. final HtmlPage page2 = button.click(); webClient.closeAllWindows(); }
/** * Logs in to Hudson. */ public WebClient login(String username, String password) throws Exception { HtmlPage page = goTo("/login"); // page = (HtmlPage) page.getFirstAnchorByText("Login").click(); HtmlForm form = page.getFormByName("login"); form.getInputByName("j_username").setValueAttribute(username); form.getInputByName("j_password").setValueAttribute(password); form.submit(null); return this; }
/** * Add a GerritServer by copying existing configs from the UI. * * @param newServerName the name of the new server * @param fromServerName the name of the server from which the config is copied. * @throws Exception if error getting URL or getting page from URL. */ private void addNewServerByCopyingConfig(String newServerName, String fromServerName) throws Exception { URL url = new URL(j.getURL(), newServerURL); HtmlPage page = j.createWebClient().getPage(url); HtmlForm form = page.getFormByName(newServerFormName); form.getInputByName(inputFormName).setValueAttribute(newServerName); List<HtmlRadioButtonInput> radioButtons = form.getRadioButtonsByName(radioButtonName); HtmlRadioButtonInput radioButtonCopy = null; for (HtmlRadioButtonInput button : radioButtons) { if (radioButtonCopyValue.equals(button.getValueAttribute())) { radioButtonCopy = button; radioButtonCopy.setChecked(true); } } assertTrue("Failed to choose 'Copy from Existing Server Configurations'", radioButtonCopy.isChecked()); form.getInputByName(fromInputFormName).setValueAttribute(fromServerName); j.submit(form); }
@Override protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception { final HtmlForm form = authorizationPage.getForms().get(0); final HtmlTextInput login = form.getInputByName("login"); login.setValueAttribute("testscribeup@gmail.com"); final HtmlPasswordInput password = form.getInputByName("password"); password.setValueAttribute("testpwdscribeup1"); final HtmlSubmitInput submit = form.getInputByName("commit"); final HtmlPage callbackPage = submit.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
/** * Remove Server from UI. * @param serverName the name of the Gerrit server you want to access. * @return true if the form had a button and was posted * @throws Exception if error removing server. */ private boolean removeServer(String serverName) throws Exception { URL url = new URL(j.getURL(), Functions.joinPath(serverURL, "server", serverName, "remove")); HtmlPage removalPage = j.createWebClient().getPage(url); HtmlForm form = removalPage.getFormByName(removalFormName); List<HtmlElement> buttons = form.getHtmlElementsByTagName("button"); textContent = form.getTextContent(); if (buttons.size() >= 1) { j.submit(form); return true; } else { return false; } }
@Override protected String getCallbackUrl(final HtmlPage authorizationPage) throws Exception { final HtmlForm form = authorizationPage.getFormByName("oauthAuthorizeForm"); final HtmlTextInput sessionKey = form.getInputByName("session_key"); sessionKey.setValueAttribute("testscribeup@gmail.com"); final HtmlPasswordInput sessionPassword = form.getInputByName("session_password"); sessionPassword.setValueAttribute("testpwdscribeup"); final HtmlSubmitInput submit = form.getInputByName("authorize"); final HtmlPage callbackPage = submit.click(); final String callbackUrl = callbackPage.getUrl().toString(); logger.debug("callbackUrl : {}", callbackUrl); return callbackUrl; }
/** * Returns the value of the JavaScript attribute "action". * @return the value of this attribute */ public String jsxGet_action() { String action = getHtmlForm().getActionAttribute(); if (getBrowserVersion().isFirefox()) { try { action = ((HtmlPage) getHtmlForm().getPage()).getFullyQualifiedUrl(action).toExternalForm(); } catch (final MalformedURLException e) { // nothing, return action attribute } } return action; }
throws IOException { if (this instanceof DisabledElement && ((DisabledElement) this).isDisabled()) { return getPage(); getPage().getWebClient().setCurrentWindow(getPage().getEnclosingWindow()); final HtmlPage page = (HtmlPage) getPage(); if (page.getFocusedElement() != this) { focus(); final WebClient webClient = page.getWebClient(); if (this instanceof HtmlTextInput || this instanceof HtmlTextArea if (!isAttachedToPage()) { final BrowserVersion browserVersion = page.getWebClient().getBrowserVersion(); if (browserVersion.hasFeature(HTMLELEMENT_DETACH_ACTIVE_TRIGGERS_NO_KEYUP_EVENT)) { eventSource = null; final HtmlForm form = getEnclosingForm(); if (form != null && c == '\n' && isSubmittableByEnter()) { final HtmlSubmitInput submit = form.getFirstByXPath(".//input[@type='submit']"); if (submit != null) { return submit.click(); form.submit((SubmittableElement) this); webClient.getJavaScriptEngine().processPostponedActions();
throws IOException { if (this instanceof DisabledElement && ((DisabledElement) this).isDisabled()) { return getPage(); if (((HtmlPage) getPage()).getFocusedElement() != this) { focus(); if (form != null && c == '\n' && isSubmittableByEnter()) { if (!ie) { final HtmlSubmitInput submit = form.getFirstByXPath(".//input[@type='submit']"); if (submit != null) { return submit.click(); return form.submit((SubmittableElement) this); return getPage();
/** * Tests rename operation. */ @Test public void rename() throws Exception { Folder f = createFolder(); f.setDescription("Some view"); String oldName = f.getName(); HtmlForm cfg = r.createWebClient().getPage(f, "confirm-rename").getFormByName("config"); cfg.getInputByName("newName").setValueAttribute("newName"); for (HtmlForm form : r.submit(cfg).getForms()) { if (form.getActionAttribute().equals("confirmRename")) { r.submit(form); break; } } assertEquals("newName",f.getName()); assertEquals("Some view",f.getDescription()); assertNull(r.jenkins.getItem(oldName)); assertSame(r.jenkins.getItem("newName"),f); }
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());
private HtmlPage submitNewRepositoryForm(HtmlPage page) throws IOException { for (HtmlForm form : page.getForms()) { for (HtmlInput mode : form.getInputsByName("mode")) { if ("new".equals(mode.getValueAttribute())) { for (HtmlInput home : form.getInputsByName("repository_home")) { home.setValueAttribute("target/repository"); for (HtmlElement submit : form.getElementsByAttribute("input", "type", "submit")) { return submit.click(); } } } } } fail(); return null; }
HtmlPage page3; page3 = webClient.getPage("Website"); HtmlForm loginForm = page3.getFormByName("loginForm"); HtmlTextInput username = loginForm.getInputByName("NameofUsernameElement"); HtmlPasswordInput pass = loginForm.getInputByName("NameofPassowordElement"); HtmlSubmitInput b = loginForm.getInputByValue("LoginButtonValue"); username.setValueAttribute("Actualy Username"); pass.setValueAttribute("Actual Password"); HtmlPage page2; page2 = b.click();
/** * Logs in to Jenkins. */ public WebClient login(String username, String password, boolean rememberMe) throws Exception { HtmlPage page = goTo("login"); // page = (HtmlPage) page.getFirstAnchorByText("Login").click(); HtmlForm form = page.getFormByName("login"); form.getInputByName("j_username").setValueAttribute(username); form.getInputByName("j_password").setValueAttribute(password); try { form.getInputByName("remember_me").setChecked(rememberMe); } catch (ElementNotFoundException e) { // remember me not available is OK so long as the caller didn't ask for it assert !rememberMe; } HtmlFormUtil.submit(form, null); return this; }
final HtmlPage htmlPage = (HtmlPage) getPage(); final WebClient webClient = htmlPage.getWebClient(); if (webClient.getOptions().isJavaScriptEnabled()) { if (submitElement != null) { isPreventDefault_ = false; if (!areChildrenValid()) { return htmlPage; final ScriptResult scriptResult = fireEvent(Event.TYPE_SUBMIT); if (isPreventDefault_) { return htmlPage; return htmlPage.getWebClient().getCurrentWindow().getEnclosedPage(); final String action = getActionAttribute().trim(); if (StringUtils.startsWithIgnoreCase(action, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { htmlPage.executeJavaScript(action, "Form action", getStartLineNumber()); return htmlPage.getWebClient().getCurrentWindow().getEnclosedPage(); if (StringUtils.startsWithIgnoreCase(getActionAttribute(), JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { updateHtml5Attributes(submitElement); final WebRequest request = getWebRequest(submitElement); final String target = htmlPage.getResolvedTarget(getTargetAttribute()); final WebWindow webWindow = htmlPage.getEnclosingWindow();
final WebClient webClient = new WebClient(); final HtmlPage page1 = webClient.getPage("http://www.facebook.com"); final HtmlForm form = (HtmlForm) page1.getElementById("login_form"); final HtmlSubmitInput button = (HtmlSubmitInput) form.getInputsByValue("Log In").get(0); final HtmlTextInput textField = form.getInputByName("email"); textField.setValueAttribute("jon@jon.com"); final HtmlPasswordInput textField2 = form.getInputByName("pass"); textField2.setValueAttribute("ahhhh"); final HtmlPage page2 = button.click();
public HtmlPage search(String q) throws IOException, SAXException { HtmlPage top = goTo(""); HtmlForm search = top.getFormByName("search"); search.getInputByName("q").setValueAttribute(q); return (HtmlPage)HtmlFormUtil.submit(search, null); }
List<HtmlElement> btns = new LinkedList<HtmlElement>(); if (form != null) { btns.addAll(getForm().getInputsByName(buttonName)); btns.addAll(getForm().getButtonsByName(buttonName)); } else { for (HtmlForm f : getCurrentPage().getForms()) { btns.addAll(f.getInputsByName(buttonName)); btns.addAll(f.getButtonsByName(buttonName)); HtmlSubmitInput btn = (HtmlSubmitInput) o; if (form == null) { form = btn.getEnclosingFormOrDie();
protected void setInputValue(HtmlPage htmlPage, HtmlForm htmlForm, String inputId, String value) { try { htmlForm.getInputByName(inputId).setValueAttribute(value); } catch (ElementNotFoundException e) { ((HtmlInput)htmlPage.getElementById(inputId)).setValueAttribute(value); } }