33import java .util .Set ;
44
55import org .apache .commons .lang .StringUtils ;
6+ import org .openqa .selenium .Keys ;
67import org .openqa .selenium .WebElement ;
78import org .slf4j .Logger ;
89import org .slf4j .LoggerFactory ;
1213import info .novatec .testit .webtester .api .callbacks .PageObjectCallback ;
1314import info .novatec .testit .webtester .api .exceptions .PageObjectIsDisabledException ;
1415import info .novatec .testit .webtester .api .exceptions .PageObjectIsInvisibleException ;
16+ import info .novatec .testit .webtester .api .exceptions .StaleElementRecoveryException ;
1517import info .novatec .testit .webtester .api .pageobjects .traits .HasText ;
1618import info .novatec .testit .webtester .eventsystem .events .pageobject .TextAppendedEvent ;
1719import info .novatec .testit .webtester .eventsystem .events .pageobject .TextClearedEvent ;
@@ -88,6 +90,11 @@ protected void executeAfterAction(TextField textField, String oldText, String ne
8890 /**
8991 * Sets the given text by replacing whatever text is currently set for the
9092 * {@link TextField text field}.
93+ * <p>
94+ * <b>Note:</b> is is not advised to try and send {@link Keys} via this method!
95+ * Doing so may in some cases lead to unintended side effects. I.e. sending ENTER
96+ * to a search field will cause a {@link StaleElementRecoveryException} if this action
97+ * navigates to another page.
9198 *
9299 * @param textToSet the text to set
93100 * @return the same instance for fluent API use
@@ -117,6 +124,11 @@ protected void executeAfterAction(TextField textField, String oldText, String ne
117124 /**
118125 * Appends the given text to whatever text is currently set for the
119126 * {@link TextField text field}.
127+ * <p>
128+ * <b>Note:</b> is is not advised to try and send {@link Keys} via this method!
129+ * Doing so may in some cases lead to unintended side effects. I.e. sending ENTER
130+ * to a search field will cause a {@link StaleElementRecoveryException} if this action
131+ * navigates to another page.
120132 *
121133 * @param textToAppend the text to append
122134 * @return the same instance for fluent API use
@@ -142,6 +154,26 @@ protected void executeAfterAction(TextField textField, String oldText, String ne
142154 return this ;
143155 }
144156
157+ /**
158+ * Presses enter on this text field. This can be for example be used to send a form where the text
159+ * field is included.
160+ * <p>
161+ * This method does <u>not</u> return this instance for fluent API because pressing ENTER is usually done in
162+ * order to send a form or otherwise execute a potentially terminal action.
163+ *
164+ * @since 1.1.0
165+ */
166+ public void pressEnter () {
167+ executeAction (new PageObjectCallback () {
168+
169+ @ Override
170+ public void execute (PageObject pageObject ) {
171+ pageObject .getWebElement ().sendKeys (Keys .ENTER );
172+ }
173+
174+ });
175+ }
176+
145177 @ Override
146178 protected boolean isCorrectClassForWebElement (WebElement webElement ) {
147179
0 commit comments