diff --git a/htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/element/Form.java b/htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/element/Form.java
index f8dadbb7..e34ad6d1 100644
--- a/htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/element/Form.java
+++ b/htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/element/Form.java
@@ -115,7 +115,7 @@ protected void fillRadio(WebElement element, String value) {
protected void fillInput(WebElement element, String value) {
TextInput input = new TextInput(element);
- input.sendKeys(input.getClearCharSequence() + value);
+ input.setText(value);
}
protected void fillSelect(WebElement element, String value) {
diff --git a/htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/element/TextInput.java b/htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/element/TextInput.java
index f20ffa13..fa41daab 100644
--- a/htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/element/TextInput.java
+++ b/htmlelements-java/src/main/java/ru/yandex/qatools/htmlelements/element/TextInput.java
@@ -36,6 +36,15 @@ public void sendKeys(CharSequence... keys) {
getWrappedElement().sendKeys(keys);
}
+ /**
+ * Sets this text input's value.
+ *
+ * @param newValue New value for this text input.
+ */
+ public void setText(String newValue) {
+ getWrappedElement().sendKeys(getClearCharSequence() + newValue);
+ }
+
/**
* @return Text entered into the text input.
* @deprecated Use getText() instead.
diff --git a/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/FormFillingTest.java b/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/FormFillingTest.java
index 09857452..eb176326 100644
--- a/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/FormFillingTest.java
+++ b/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/FormFillingTest.java
@@ -24,7 +24,6 @@ public void fillForm() {
// Prepare data to fill form with
Map data = new HashMap();
data.put(MockedForm.TEXT_INPUT_NAME, INPUT_TEXT_TO_SEND);
- data.put(MockedForm.TEXT_INPUT_WITH_TEXT_NAME, INPUT_TEXT_TO_SEND);
data.put(MockedForm.CHECKBOX_NAME, CHECKBOX_VALUE_TO_SET);
data.put(MockedForm.RADIO_NAME, MockedForm.RADIO_BUTTON_VALUE);
data.put(MockedForm.SELECT_NAME, MockedForm.SELECT_OPTION_VALUE);
@@ -39,7 +38,6 @@ public void fillForm() {
public void formFieldsShouldBeFilledCorrectly() {
fillForm();
verify(form.getTextInput()).sendKeys(INPUT_TEXT_TO_SEND);
- verify(form.getTextInputWithText()).sendKeys(INPUT_WITH_TEXT_KEYS_TO_SEND);
verify(form.getCheckBox()).click();
verify(form.getRadioButton()).click();
verify(form.getSelectOption()).click();
diff --git a/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/TextInputSetTextMethodTest.java b/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/TextInputSetTextMethodTest.java
new file mode 100644
index 00000000..0e866815
--- /dev/null
+++ b/htmlelements-java/src/test/java/ru/yandex/qatools/htmlelements/TextInputSetTextMethodTest.java
@@ -0,0 +1,33 @@
+package ru.yandex.qatools.htmlelements;
+
+import org.junit.Test;
+import org.openqa.selenium.Keys;
+import org.openqa.selenium.WebElement;
+import ru.yandex.qatools.htmlelements.element.TextInput;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Alexander Kedrik alkedr@yandex-team.ru
+ * Date: 08.09.15
+ */
+public class TextInputSetTextMethodTest {
+ private final WebElement webElement = mock(WebElement.class);
+ private final TextInput textInput = new TextInput(webElement);
+
+ @Test
+ public void setTextShouldNotAddClearKeysForTextInputWithEmptyText() {
+ when(webElement.getAttribute("value")).thenReturn("");
+ textInput.setText("qwerty");
+ verify(webElement).sendKeys("qwerty");
+ }
+
+ @Test
+ public void setTextShouldAddClearKeysForTextInputWithNonEmptyText() {
+ when(webElement.getAttribute("value")).thenReturn("12");
+ textInput.setText("qwerty");
+ verify(webElement).sendKeys(Keys.DELETE.toString() + Keys.BACK_SPACE + Keys.DELETE + Keys.BACK_SPACE + "qwerty");
+ }
+}