-
-
Notifications
You must be signed in to change notification settings - Fork 181
Closed
Description
The Migrating from HtmlUnit 2.x.x to HtmlUnit 3.x.x documentation states:
Replace all usages of
org.htmlunit.html.HtmlInput.getValueAttribute()
byorg.htmlunit.html.HtmlInput.getValue()
. Replace all usages oforg.htmlunit.html.HtmlInput.setValueAttribute(String)
byorg.htmlunit.html.HtmlInput.setValue(String)
.
The problem is that once you do this, org.htmlunit.html.HtmlForm#getInputByValue
and org.htmlunit.html.HtmlForm#getInputsByValue
stop working, since they internally use org.htmlunit.html.DomElement#getAttributeDirect("value")
rather than org.htmlunit.html.HtmlInput#getValue
. Observed after debugging the test failures in jenkinsci/jenkins#8050.
Workaround:
/**
* Returns the first input in this form with the specified value.
* @param value the value to search for
* @return the first input in this form with the specified value
* @throws ElementNotFoundException if this form does not contain any inputs with the specified value
*/
private static HtmlInput getInputByValue(final HtmlForm f, final String value) throws ElementNotFoundException {
// TODO org.htmlunit.html.HtmlForm#getInputByValue is busted
return f.getInputsByValue("").stream()
.filter(HtmlInput.class::isInstance)
.map(HtmlInput.class::cast)
.filter(input -> input.getValue().equals(value))
.findFirst()
.orElseThrow(() -> new ElementNotFoundException("input", "value", value));
}
/**
* Returns all the inputs in this form with the specified value.
* @param value the value to search for
* @return all the inputs in this form with the specified value
*/
private static List<HtmlInput> getInputsByValue(final HtmlForm f, final String value) {
// TODO org.htmlunit.html.HtmlForm#getInputsByValue is busted
return f.getInputsByValue("").stream()
.filter(HtmlInput.class::isInstance)
.map(HtmlInput.class::cast)
.filter(input -> input.getValue().equals(value))
.collect(Collectors.toList());
}
CC @rbri
Metadata
Metadata
Assignees
Labels
No labels