2020
2121from SeleniumLibrary .base import LibraryComponent , keyword
2222from SeleniumLibrary .errors import ElementNotFound
23- from SeleniumLibrary .utils .types import Locator
23+ from SeleniumLibrary .utils .types import Locator , Secret
2424
2525
2626class FormElementKeywords (LibraryComponent ):
@@ -238,7 +238,9 @@ def choose_file(self, locator: Locator, file_path: str):
238238 self .ctx ._running_keyword = None
239239
240240 @keyword
241- def input_password (self , locator : Locator , password : str , clear : bool = True ):
241+ def input_password (
242+ self , locator : Locator , password : str | Secret , clear : bool = True
243+ ):
242244 """Types the given password into the text field identified by ``locator``.
243245
244246 See the `Locating elements` section for details about the locator
@@ -256,8 +258,15 @@ def input_password(self, locator: Locator, password: str, clear: bool = True):
256258 | Input Password | password_field | ${PASSWORD} |
257259
258260 Please notice that Robot Framework logs all arguments using
259- the TRACE level and tests must not be executed using level below
260- DEBUG if the password should not be logged in any format.
261+ the TRACE level. When not using the ``Secret`` type, tests must
262+ not be executed using level below DEBUG if the password should
263+ not be logged in any format.
264+
265+ This keyword supports Robot Framework 7.4
266+ [https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#secret-variables|Secret]
267+ variable type. When a ``Secret`` is passed, the value is protected
268+ from Robot Framework logs and Selenium internal logging is also
269+ suppressed during typing.
261270
262271 The `clear` argument is new in SeleniumLibrary 4.0. Hiding password
263272 logging from Selenium logs is new in SeleniumLibrary 4.2.
@@ -266,14 +275,21 @@ def input_password(self, locator: Locator, password: str, clear: bool = True):
266275 self ._input_text_into_text_field (locator , password , clear , disable_log = True )
267276
268277 @keyword
269- def input_text (self , locator : Locator , text : str , clear : bool = True ):
278+ def input_text (self , locator : Locator , text : str | Secret , clear : bool = True ):
270279 """Types the given ``text`` into the text field identified by ``locator``.
271280
272281 When ``clear`` is true, the input element is cleared before
273282 the text is typed into the element. When false, the previous text
274283 is not cleared from the element. Use `Input Password` if you
275284 do not want the given ``text`` to be logged.
276285
286+ This keyword supports Robot Framework 7.4
287+ [https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#secret-variables|Secret]
288+ variable type. When a ``Secret`` is passed, the value is masked in
289+ Robot Framework logs and Selenium's internal logs are suppressed during
290+ typing. When a plain string is passed, Selenium's internal logs are not
291+ suppressed.
292+
277293 If [https://github.com/SeleniumHQ/selenium/wiki/Grid2|Selenium Grid]
278294 is used and the ``text`` argument points to a file in the file system,
279295 then this keyword prevents the Selenium to transfer the file to the
@@ -289,7 +305,9 @@ def input_text(self, locator: Locator, text: str, clear: bool = True):
289305 argument are new in SeleniumLibrary 4.0
290306 """
291307 self .info (f"Typing text '{ text } ' into text field '{ locator } '." )
292- self ._input_text_into_text_field (locator , text , clear )
308+ self ._input_text_into_text_field (
309+ locator , text , clear , disable_log = isinstance (text , Secret )
310+ )
293311
294312 @keyword
295313 def page_should_contain_textfield (
@@ -502,7 +520,7 @@ def _input_text_into_text_field(self, locator, text, clear=True, disable_log=Fal
502520 self .info ("Temporally setting log level to: NONE" )
503521 previous_level = BuiltIn ().set_log_level ("NONE" )
504522 try :
505- element .send_keys (text )
523+ element .send_keys (text . value if isinstance ( text , Secret ) else text )
506524 finally :
507525 if disable_log :
508526 BuiltIn ().set_log_level (previous_level )
0 commit comments