Skip to content
Permalink
Browse files

[JENKINS-31631] Handle YUI submit <button> clicks

(cherry picked from commit 7fdb589133de09e77d29397ee01bcc9004e25cb2)

Originally-Committed-As: 5defc349a8894bbc6dd524e6f9ba9c1fc5662e52
  • Loading branch information
tfennelly authored and olivergondza committed Nov 24, 2015
1 parent a0db0c3 commit bd76ca4d585295ca2395ed14868a7d7423932d44
@@ -28,6 +28,9 @@
import com.gargoylesoftware.htmlunit.WebClientUtil;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
* {@link HtmlElement} helper methods.
@@ -58,4 +61,16 @@ public static Page click(HtmlElement element) throws IOException {
WebClientUtil.waitForJSExec(webClient);
}
}

/**
* Does the supplied element define the specified HTML "class" name.
* @param element The element to check.
* @param className The HTML "class" name to check for.
* @return {@code true} if the element defines the specified class, otherwise {@code false}.
*/
public static boolean hasClassName(HtmlElement element, String className) {
String classAttribute = element.getAttribute("class");
Set<String> classes = new HashSet<>(Arrays.asList(classAttribute.split(" ")));
return classes.contains(className);
}
}
@@ -37,6 +37,7 @@
import com.gargoylesoftware.htmlunit.html.DomNode;
import com.gargoylesoftware.htmlunit.html.HtmlButton;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlElementUtil;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlImage;
import com.gargoylesoftware.htmlunit.html.HtmlInput;
@@ -1342,9 +1343,12 @@ public HtmlPage submit(HtmlForm form) throws Exception {
*/
public HtmlPage submit(HtmlForm form, String name) throws Exception {
for( HtmlElement e : form.getHtmlElementsByTagName("button")) {
HtmlElement p = (HtmlElement)e.getParentNode().getParentNode();
if(e instanceof HtmlButton && p.getAttribute("name").equals(name)) {
return (HtmlPage)HtmlFormUtil.submit(form, (HtmlButton) e);
HtmlElement p = (HtmlElement)e.getParentNode().getParentNode();
if (p.getAttribute("name").equals(name) && HtmlElementUtil.hasClassName(p, "yui-submit-button")) {
// For YUI handled submit buttons, just do a click.
return (HtmlPage) HtmlElementUtil.click(e);
} else if (e.getAttribute("name").equals(name)) {
return (HtmlPage) HtmlFormUtil.submit(form, e);
}
}
throw new AssertionError("No such submit button with the name "+name);

0 comments on commit bd76ca4

Please sign in to comment.
You can’t perform that action at this time.