Skip to content

Commit 1344bb5

Browse files
committed
clearing a number input with invalid text, should actually clear it.
Fixes #1214
1 parent ffaf288 commit 1344bb5

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

java/client/test/org/openqa/selenium/TypingTest.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import static org.junit.Assert.assertThat;
2626
import static org.junit.Assume.assumeFalse;
2727
import static org.openqa.selenium.WaitingConditions.elementValueToEqual;
28-
import static org.openqa.selenium.testing.Ignore.Driver.ALL;
2928
import static org.openqa.selenium.testing.Ignore.Driver.CHROME;
3029
import static org.openqa.selenium.testing.Ignore.Driver.HTMLUNIT;
3130
import static org.openqa.selenium.testing.Ignore.Driver.IE;
@@ -781,6 +780,16 @@ public void canSafelyTypeOnElementThatIsRemovedFromTheDomOnKeyPress() {
781780
assertThat(getValueText(log), anyOf(equalTo(expected), equalTo(expected + "\nkeyup (body)")));
782781
}
783782

783+
@Test
784+
public void canClearNumberInputAfterTypingInvalidInput() {
785+
driver.get(pages.formPage);
786+
WebElement input = driver.findElement(By.id("age"));
787+
input.sendKeys("e");
788+
input.clear();
789+
input.sendKeys("3");
790+
assertEquals("3", input.getAttribute("value"));
791+
}
792+
784793
private static String getValueText(WebElement el) {
785794
// Standardize on \n and strip any trailing whitespace.
786795
return el.getAttribute("value").replace("\r\n", "\n").trim();

javascript/atoms/action.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ bot.action.clear = function(element) {
9191
if (element.value) {
9292
element.value = '';
9393
bot.events.fire(element, bot.events.EventType.CHANGE);
94+
} else if (bot.dom.isElement(element, goog.dom.TagName.INPUT) &&
95+
element.getAttribute('type').toLowerCase() == "number") {
96+
// number input fields that have invalid inputs
97+
// report their value as empty string with no way to tell if there is a
98+
// current value or not
99+
element.value = '';
94100
}
95101

96102
if (bot.dom.isContentEditable(element)) {

0 commit comments

Comments
 (0)