/** * Finds the form in the html document that performs the provided action. * * @param action the action to search for. * @param forms the html forms in the document. * @return the form, or null of there is none. */ public static HtmlForm getFormWithAction(String action, List<HtmlForm> forms) { for (HtmlForm f : forms) { if (f.getActionAttribute().equalsIgnoreCase(action)) { return f; } } return null; }
private HtmlForm findForm(HtmlPage page, String action) { for (HtmlForm form: page.getForms()) { if (action.equals(form.getActionAttribute())) { return form; } } fail("no form found"); return null; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * Returns the value of the property {@code action}. * @return the value of this property */ @JsxGetter public String getAction() { final String action = getHtmlForm().getActionAttribute(); if (action != DomElement.ATTRIBUTE_NOT_DEFINED && action.length() == 0 && getBrowserVersion().hasFeature(JS_FORM_ACTION_EXPANDURL_IGNORE_EMPTY)) { return action; } if (action == DomElement.ATTRIBUTE_NOT_DEFINED && !getBrowserVersion().hasFeature(JS_FORM_ACTION_EXPANDURL_NOT_DEFINED)) { return action; } try { return ((HtmlPage) getHtmlForm().getPage()).getFullyQualifiedUrl(action).toExternalForm(); } catch (final MalformedURLException e) { // nothing, return action attribute } return action; }
/** * Returns the value of the property {@code action}. * @return the value of this property */ @JsxGetter public String getAction() { final String action = getHtmlForm().getActionAttribute(); if (action != DomElement.ATTRIBUTE_NOT_DEFINED && action.length() == 0 && getBrowserVersion().hasFeature(JS_FORM_ACTION_EXPANDURL_IGNORE_EMPTY)) { return action; } if (action == DomElement.ATTRIBUTE_NOT_DEFINED && !getBrowserVersion().hasFeature(JS_FORM_ACTION_EXPANDURL_NOT_DEFINED)) { return action; } try { return ((HtmlPage) getHtmlForm().getPage()).getFullyQualifiedUrl(action).toExternalForm(); } catch (final MalformedURLException e) { // nothing, return action attribute } return action; }
final String action = getActionAttribute(); if (TextUtil.startsWithIgnoreCase(action, JAVASCRIPT_PREFIX)) { return htmlPage.executeJavaScriptIfPossible(action, "Form action", getStartLineNumber()).getNewPage(); if (TextUtil.startsWithIgnoreCase(getActionAttribute(), JAVASCRIPT_PREFIX)) { String actionUrl = getActionAttribute(); if (HttpMethod.GET == method) { final String anchor = StringUtils.substringAfter(actionUrl, "#");
final String action = getActionAttribute(); if (TextUtil.startsWithIgnoreCase(action, JAVASCRIPT_PREFIX)) { return htmlPage.executeJavaScriptIfPossible(action, "Form action", getStartLineNumber()).getNewPage(); if (TextUtil.startsWithIgnoreCase(getActionAttribute(), JAVASCRIPT_PREFIX)) { String actionUrl = getActionAttribute(); if (HttpMethod.GET == method) { final String anchor = StringUtils.substringAfter(actionUrl, "#");
final String action = getActionAttribute(); if (TextUtil.startsWithIgnoreCase(action, JAVASCRIPT_PREFIX)) { return htmlPage.executeJavaScriptIfPossible(action, "Form action", getStartLineNumber()).getNewPage(); if (TextUtil.startsWithIgnoreCase(getActionAttribute(), JAVASCRIPT_PREFIX)) { String actionUrl = getActionAttribute(); if (HttpMethod.GET == method) { final String anchor = StringUtils.substringAfter(actionUrl, "#");
/** * Submits the form (at the end of the current script execution). */ @JsxFunction public void submit() { final HtmlPage page = (HtmlPage) getDomNodeOrDie().getPage(); final WebClient webClient = page.getWebClient(); final String action = getHtmlForm().getActionAttribute().trim(); if (StringUtils.startsWithIgnoreCase(action, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { final String js = action.substring(JavaScriptURLConnection.JAVASCRIPT_PREFIX.length()); webClient.getJavaScriptEngine().execute(page, js, "Form action", 0); } else { // download should be done ASAP, response will be loaded into a window later final WebRequest request = getHtmlForm().getWebRequest(null); final String target = page.getResolvedTarget(getTarget()); final boolean forceDownload = webClient.getBrowserVersion().hasFeature(JS_FORM_SUBMIT_FORCES_DOWNLOAD); final boolean checkHash = !webClient.getBrowserVersion().hasFeature(FORM_SUBMISSION_DOWNLOWDS_ALSO_IF_ONLY_HASH_CHANGED); webClient.download(page.getEnclosingWindow(), target, request, checkHash, forceDownload, "JS form.submit()"); } }
/** * Submits the form (at the end of the current script execution). */ @JsxFunction public void submit() { final HtmlPage page = (HtmlPage) getDomNodeOrDie().getPage(); final WebClient webClient = page.getWebClient(); final String action = getHtmlForm().getActionAttribute().trim(); if (StringUtils.startsWithIgnoreCase(action, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { final String js = action.substring(JavaScriptURLConnection.JAVASCRIPT_PREFIX.length()); webClient.getJavaScriptEngine().execute(page, js, "Form action", 0); } else { // download should be done ASAP, response will be loaded into a window later final WebRequest request = getHtmlForm().getWebRequest(null); final String target = page.getResolvedTarget(getTarget()); final boolean forceDownload = webClient.getBrowserVersion().hasFeature(JS_FORM_SUBMIT_FORCES_DOWNLOAD); final boolean checkHash = !webClient.getBrowserVersion().hasFeature(FORM_SUBMISSION_DOWNLOWDS_ALSO_IF_ONLY_HASH_CHANGED); webClient.download(page.getEnclosingWindow(), target, request, checkHash, forceDownload, "JS form.submit()"); } }
String actionUrl = getActionAttribute(); String anchor = null; String queryFormFields = "";
String actionUrl = getActionAttribute(); String anchor = null; String queryFormFields = "";
final String action = getActionAttribute().trim(); if (StringUtils.startsWithIgnoreCase(action, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { htmlPage.executeJavaScript(action, "Form action", getStartLineNumber()); if (StringUtils.startsWithIgnoreCase(getActionAttribute(), JavaScriptURLConnection.JAVASCRIPT_PREFIX)) {
final String action = getActionAttribute().trim(); if (StringUtils.startsWithIgnoreCase(action, JavaScriptURLConnection.JAVASCRIPT_PREFIX)) { htmlPage.executeJavaScript(action, "Form action", getStartLineNumber()); if (StringUtils.startsWithIgnoreCase(getActionAttribute(), JavaScriptURLConnection.JAVASCRIPT_PREFIX)) {
/** * 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); }