Skip to content

Commit

Permalink
introduce HtmlInput.getValue() & HtmlInput.setValue(String)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbri committed Jun 1, 2022
1 parent 98ed2a8 commit ea052c9
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<body>
<release version="2.62.0" date="May xx, 2022" description="Chrome/Edge 102, Firefox 101, Bugfixes">
<action> type="add" dev="rbri">
Introduce HtmlInput.getValue().
Introduce HtmlInput.getValue() & HtmlInput.setValue(String).
</action>
<action type="fix" dev="rbri" due-to="Rural Hunter">
core-js: Fix Object.getOwnPropertyDescriptors by fixing missing scope definitions.
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/gargoylesoftware/htmlunit/WebAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public static void assertInputContainsValue(final HtmlPage page, final String na
throw new AssertionError("Unable to find an input element named '" + name + "'.");
}
final HtmlInput input = (HtmlInput) list.get(0);
final String s = input.getValueAttribute();
final String s = input.getValue();
if (!s.equals(value)) {
throw new AssertionError("The input element named '" + name + "' contains the value '" + s
+ "', not the expected value '" + value + "'.");
Expand All @@ -391,7 +391,7 @@ public static void assertInputDoesNotContainValue(final HtmlPage page, final Str
throw new AssertionError("Unable to find an input element named '" + name + "'.");
}
final HtmlInput input = (HtmlInput) list.get(0);
final String s = input.getValueAttribute();
final String s = input.getValue();
if (s.equals(value)) {
throw new AssertionError("The input element named '" + name + "' contains the value '" + s
+ "', not the expected value '" + value + "'.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,14 +786,14 @@ private static boolean selectsPseudoClass(final BrowserVersion browserVersion,
case "placeholder-shown":
if (browserVersion.hasFeature(CSS_PSEUDO_SELECTOR_PLACEHOLDER_SHOWN)) {
return element instanceof HtmlInput
&& StringUtils.isEmpty(((HtmlInput) element).getValueAttribute())
&& StringUtils.isEmpty(((HtmlInput) element).getValue())
&& StringUtils.isNotEmpty(((HtmlInput) element).getPlaceholder());
}

case "-ms-input-placeholder":
if (browserVersion.hasFeature(CSS_PSEUDO_SELECTOR_MS_PLACEHHOLDER)) {
return element instanceof HtmlInput
&& StringUtils.isEmpty(((HtmlInput) element).getValueAttribute())
&& StringUtils.isEmpty(((HtmlInput) element).getValue())
&& StringUtils.isNotEmpty(((HtmlInput) element).getPlaceholder());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ public String getValue() {
return getValueAttribute();
}

/**
* Sets the value.
*
* @param newValue the new value
*/
public void setValue(final String newValue) {
setValueAttribute(newValue);
}

/**
* Returns the value of the attribute {@code checked}. Refer to the
* <a href='http://www.w3.org/TR/html401/'>HTML 4.01</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ else if (browser.hasFeature(JS_INPUT_SET_UNSUPORTED_TYPE_EXCEPTION)) {
@Override
public void setValue(final Object newValue) {
if (null == newValue) {
getDomNodeOrDie().setValueAttribute("");
getDomNodeOrDie().setValue("");
getDomNodeOrDie().valueModifiedByJavascript();
return;
}
Expand All @@ -252,7 +252,7 @@ public void setValue(final Object newValue) {
return;
}

getDomNodeOrDie().setValueAttribute(val);
getDomNodeOrDie().setValue(val);
getDomNodeOrDie().valueModifiedByJavascript();
}

Expand Down

0 comments on commit ea052c9

Please sign in to comment.