Skip to content
Permalink
Browse files

Merge pull request #1918 from tfennelly/htmlunit-fixes

[Fixed JENKINS-31631] Handle YUI submit <button> clicks
  • Loading branch information
tfennelly committed Nov 19, 2015
2 parents d00dc71 + 7fdb589 commit 23276180209b40315d19ea1c143b69d348d607ae
@@ -150,6 +150,12 @@ THE SOFTWARE.
<groupId>org.jvnet.hudson</groupId>
<artifactId>embedded-rhino-debugger</artifactId>
<version>1.2</version>
<exclusions>
<exclusion>
<groupId>org.jvnet.hudson</groupId>
<artifactId>htmlunit-core-js</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<!-- for testing JNLP launch. -->
@@ -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;
@@ -1341,9 +1342,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 2327618

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