1818
1919from SeleniumLibrary .base import LibraryComponent , keyword
2020from SeleniumLibrary .errors import ElementNotFound
21- from SeleniumLibrary .utils import is_noney
21+ from SeleniumLibrary .utils import is_noney , is_truthy
2222
2323
2424class FormElementKeywords (LibraryComponent ):
@@ -213,11 +213,11 @@ def choose_file(self, locator, file_path):
213213 self .find_element (locator ).send_keys (file_path )
214214
215215 @keyword
216- def input_password (self , locator , password ):
216+ def input_password (self , locator , password , clear = True ):
217217 """Types the given password into text field identified by ``locator``.
218218
219219 See the `Locating elements` section for details about the locator
220- syntax.
220+ syntax. See `Input Text` for ``clear`` argument details.
221221
222222 Difference compared to `Input Text` is that this keyword does not
223223 log the given password on the INFO level. Notice that if you use
@@ -235,22 +235,29 @@ def input_password(self, locator, password):
235235 be seen there. Additionally Robot Framework logs all arguments using
236236 the TRACE level. Tests must thus not be executed using level below
237237 INFO if password should not be logged in any format.
238+
239+ The `clear` argument is new in SeleniumLibrary 4.0
238240 """
239241 self .info ("Typing password into text field '%s'." % locator )
240- self ._input_text_into_text_field (locator , password )
242+ self ._input_text_into_text_field (locator , password , clear )
241243
242244 @keyword
243- def input_text (self , locator , text ):
245+ def input_text (self , locator , text , clear = True ):
244246 """Types the given ``text`` into text field identified by ``locator``.
245247
246- Use `Input Password` if you do not want the given ``text`` to be
247- logged.
248+ When ``clear`` is true, the input element is cleared before
249+ text is typed to the element. When false, the previous text
250+ is not cleared from the element. Use `Input Password` if you
251+ do not want the given ``text`` to be logged.
248252
249253 See the `Locating elements` section for details about the locator
250- syntax.
254+ syntax. See the `Boolean arguments` section how Boolean values are
255+ handled.
256+
257+ The `clear` argument is new in SeleniumLibrary 4.0
251258 """
252259 self .info ("Typing text '%s' into text field '%s'." % (text , locator ))
253- self ._input_text_into_text_field (locator , text )
260+ self ._input_text_into_text_field (locator , text , clear )
254261
255262 @keyword
256263 def page_should_contain_textfield (self , locator , message = None , loglevel = 'TRACE' ):
@@ -405,7 +412,8 @@ def _get_value_from_radio_buttons(self, elements):
405412 return element .get_attribute ('value' )
406413 return None
407414
408- def _input_text_into_text_field (self , locator , text ):
415+ def _input_text_into_text_field (self , locator , text , clear ):
409416 element = self .find_element (locator )
410- element .clear ()
417+ if is_truthy (clear ):
418+ element .clear ()
411419 element .send_keys (text )
0 commit comments