diff --git a/java/client/src/org/openqa/selenium/remote/RemoteWebElement.java b/java/client/src/org/openqa/selenium/remote/RemoteWebElement.java index f142c816b40d3..dd7fe7554dc29 100644 --- a/java/client/src/org/openqa/selenium/remote/RemoteWebElement.java +++ b/java/client/src/org/openqa/selenium/remote/RemoteWebElement.java @@ -106,7 +106,7 @@ public void sendKeys(CharSequence... keysToSend) { List files = Arrays.stream(allKeysToSend.split("\n")) .map(fileDetector::getLocalFile) .collect(Collectors.toList()); - if (! files.contains(null)) { + if (!files.isEmpty() && !files.contains(null)) { allKeysToSend = files.stream() .map(this::upload) .collect(Collectors.joining("\n")); diff --git a/java/client/test/org/openqa/selenium/TypingTest.java b/java/client/test/org/openqa/selenium/TypingTest.java index 2e652c8db44a4..c18bc75ce3efe 100644 --- a/java/client/test/org/openqa/selenium/TypingTest.java +++ b/java/client/test/org/openqa/selenium/TypingTest.java @@ -30,6 +30,7 @@ import static org.openqa.selenium.testing.TestUtilities.isFirefox; import org.junit.Test; +import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.testing.Ignore; import org.openqa.selenium.testing.JUnit4TestBase; import org.openqa.selenium.testing.NotYetImplemented; @@ -657,6 +658,22 @@ public void canClearNumberInputAfterTypingInvalidInput() { assertThat(input.getAttribute("value")).isEqualTo("3"); } + @Test + public void canTypeSingleNewLineCharacterIntoTextArea() { + driver.get(pages.formPage); + WebElement element = driver.findElement(By.id("emptyTextArea")); + element.sendKeys("\n"); + shortWait.until(ExpectedConditions.attributeToBe(element, "value", "\n")); + } + + @Test + public void canTypeMultipleNewLineCharactersIntoTextArea() { + driver.get(pages.formPage); + WebElement element = driver.findElement(By.id("emptyTextArea")); + element.sendKeys("\n\n\n"); + shortWait.until(ExpectedConditions.attributeToBe(element, "value", "\n\n\n")); + } + private static String getValueText(WebElement el) { // Standardize on \n and strip any trailing whitespace. return el.getAttribute("value").replace("\r\n", "\n").trim();