1515# limitations under the License.
1616
1717import os
18- from typing import Optional
18+ from typing import Optional , Union
1919
2020from robot .libraries .BuiltIn import BuiltIn
21+ from selenium .webdriver .remote .webelement import WebElement
2122
2223from SeleniumLibrary .base import LibraryComponent , keyword
2324from SeleniumLibrary .errors import ElementNotFound
2425
2526
2627class FormElementKeywords (LibraryComponent ):
2728 @keyword
28- def submit_form (self , locator : Optional [ str ] = None ):
29+ def submit_form (self , locator : Union [ WebElement , None , str ] = None ):
2930 """Submits a form identified by ``locator``.
3031
3132 If ``locator`` is not given, first form on the page is submitted.
@@ -40,7 +41,7 @@ def submit_form(self, locator: Optional[str] = None):
4041 element .submit ()
4142
4243 @keyword
43- def checkbox_should_be_selected (self , locator : str ):
44+ def checkbox_should_be_selected (self , locator : Union [ WebElement , str ] ):
4445 """Verifies checkbox ``locator`` is selected/checked.
4546
4647 See the `Locating elements` section for details about the locator
@@ -54,7 +55,7 @@ def checkbox_should_be_selected(self, locator: str):
5455 )
5556
5657 @keyword
57- def checkbox_should_not_be_selected (self , locator : str ):
58+ def checkbox_should_not_be_selected (self , locator : Union [ WebElement , str ] ):
5859 """Verifies checkbox ``locator`` is not selected/checked.
5960
6061 See the `Locating elements` section for details about the locator
@@ -67,7 +68,7 @@ def checkbox_should_not_be_selected(self, locator: str):
6768
6869 @keyword
6970 def page_should_contain_checkbox (
70- self , locator : str , message : Optional [str ] = None , loglevel : str = "TRACE"
71+ self , locator : Union [ WebElement , str ] , message : Optional [str ] = None , loglevel : str = "TRACE"
7172 ):
7273 """Verifies checkbox ``locator`` is found from the current page.
7374
@@ -81,7 +82,7 @@ def page_should_contain_checkbox(
8182
8283 @keyword
8384 def page_should_not_contain_checkbox (
84- self , locator : str , message : Optional [str ] = None , loglevel : str = "TRACE"
85+ self , locator : Union [ WebElement , str ] , message : Optional [str ] = None , loglevel : str = "TRACE"
8586 ):
8687 """Verifies checkbox ``locator`` is not found from the current page.
8788
@@ -94,7 +95,7 @@ def page_should_not_contain_checkbox(
9495 self .assert_page_not_contains (locator , "checkbox" , message , loglevel )
9596
9697 @keyword
97- def select_checkbox (self , locator : str ):
98+ def select_checkbox (self , locator : Union [ WebElement , str ] ):
9899 """Selects the checkbox identified by ``locator``.
99100
100101 Does nothing if checkbox is already selected.
@@ -108,7 +109,7 @@ def select_checkbox(self, locator: str):
108109 element .click ()
109110
110111 @keyword
111- def unselect_checkbox (self , locator : str ):
112+ def unselect_checkbox (self , locator : Union [ WebElement , str ] ):
112113 """Removes the selection of checkbox identified by ``locator``.
113114
114115 Does nothing if the checkbox is not selected.
@@ -123,7 +124,7 @@ def unselect_checkbox(self, locator: str):
123124
124125 @keyword
125126 def page_should_contain_radio_button (
126- self , locator : str , message : Optional [str ] = None , loglevel : str = "TRACE"
127+ self , locator : Union [ WebElement , str ] , message : Optional [str ] = None , loglevel : str = "TRACE"
127128 ):
128129 """Verifies radio button ``locator`` is found from current page.
129130
@@ -138,7 +139,7 @@ def page_should_contain_radio_button(
138139
139140 @keyword
140141 def page_should_not_contain_radio_button (
141- self , locator : str , message : Optional [str ] = None , loglevel : str = "TRACE"
142+ self , locator : Union [ WebElement , str ] , message : Optional [str ] = None , loglevel : str = "TRACE"
142143 ):
143144 """Verifies radio button ``locator`` is not found from current page.
144145
@@ -200,7 +201,7 @@ def select_radio_button(self, group_name: str, value: str):
200201 element .click ()
201202
202203 @keyword
203- def choose_file (self , locator : str , file_path : str ):
204+ def choose_file (self , locator : Union [ WebElement , str ] , file_path : str ):
204205 """Inputs the ``file_path`` into the file input field ``locator``.
205206
206207 This keyword is most often used to input files into upload forms.
@@ -226,7 +227,7 @@ def choose_file(self, locator: str, file_path: str):
226227 self .ctx ._running_keyword = None
227228
228229 @keyword
229- def input_password (self , locator : str , password : str , clear : bool = True ):
230+ def input_password (self , locator : Union [ WebElement , str ] , password : str , clear : bool = True ):
230231 """Types the given password into the text field identified by ``locator``.
231232
232233 See the `Locating elements` section for details about the locator
@@ -254,7 +255,7 @@ def input_password(self, locator: str, password: str, clear: bool = True):
254255 self ._input_text_into_text_field (locator , password , clear , disable_log = True )
255256
256257 @keyword
257- def input_text (self , locator : str , text : str , clear : bool = True ):
258+ def input_text (self , locator : Union [ WebElement , str ] , text : str , clear : bool = True ):
258259 """Types the given ``text`` into the text field identified by ``locator``.
259260
260261 When ``clear`` is true, the input element is cleared before
@@ -281,7 +282,7 @@ def input_text(self, locator: str, text: str, clear: bool = True):
281282
282283 @keyword
283284 def page_should_contain_textfield (
284- self , locator : str , message : Optional [str ] = None , loglevel : str = "TRACE"
285+ self , locator : Union [ WebElement , str ] , message : Optional [str ] = None , loglevel : str = "TRACE"
285286 ):
286287 """Verifies text field ``locator`` is found from current page.
287288
@@ -295,7 +296,7 @@ def page_should_contain_textfield(
295296
296297 @keyword
297298 def page_should_not_contain_textfield (
298- self , locator : str , message : Optional [str ] = None , loglevel : str = "TRACE"
299+ self , locator : Union [ WebElement , str ] , message : Optional [str ] = None , loglevel : str = "TRACE"
299300 ):
300301 """Verifies text field ``locator`` is not found from current page.
301302
@@ -309,7 +310,7 @@ def page_should_not_contain_textfield(
309310
310311 @keyword
311312 def textfield_should_contain (
312- self , locator : str , expected : str , message : Optional [str ] = None
313+ self , locator : Union [ WebElement , str ] , expected : str , message : Optional [str ] = None
313314 ):
314315 """Verifies text field ``locator`` contains text ``expected``.
315316
@@ -330,7 +331,7 @@ def textfield_should_contain(
330331
331332 @keyword
332333 def textfield_value_should_be (
333- self , locator : str , expected : str , message : Optional [str ] = None
334+ self , locator : Union [ WebElement , str ] , expected : str , message : Optional [str ] = None
334335 ):
335336 """Verifies text field ``locator`` has exactly text ``expected``.
336337
@@ -351,7 +352,7 @@ def textfield_value_should_be(
351352
352353 @keyword
353354 def textarea_should_contain (
354- self , locator : str , expected : str , message : Optional [str ] = None
355+ self , locator : Union [ WebElement , str ] , expected : str , message : Optional [str ] = None
355356 ):
356357 """Verifies text area ``locator`` contains text ``expected``.
357358
@@ -372,7 +373,7 @@ def textarea_should_contain(
372373
373374 @keyword
374375 def textarea_value_should_be (
375- self , locator : str , expected : str , message : Optional [str ] = None
376+ self , locator : Union [ WebElement , str ] , expected : str , message : Optional [str ] = None
376377 ):
377378 """Verifies text area ``locator`` has exactly text ``expected``.
378379
@@ -393,7 +394,7 @@ def textarea_value_should_be(
393394
394395 @keyword
395396 def page_should_contain_button (
396- self , locator : str , message : Optional [str ] = None , loglevel : str = "TRACE"
397+ self , locator : Union [ WebElement , str ] , message : Optional [str ] = None , loglevel : str = "TRACE"
397398 ):
398399 """Verifies button ``locator`` is found from current page.
399400
@@ -411,7 +412,7 @@ def page_should_contain_button(
411412
412413 @keyword
413414 def page_should_not_contain_button (
414- self , locator : str , message : Optional [str ] = None , loglevel : str = "TRACE"
415+ self , locator : Union [ WebElement , str ] , message : Optional [str ] = None , loglevel : str = "TRACE"
415416 ):
416417 """Verifies button ``locator`` is not found from current page.
417418
@@ -428,7 +429,7 @@ def page_should_not_contain_button(
428429 def _get_value (self , locator , tag ):
429430 return self .find_element (locator , tag ).get_attribute ("value" )
430431
431- def _get_checkbox (self , locator ):
432+ def _get_checkbox (self , locator : Union [ WebElement , str ] ):
432433 return self .find_element (locator , tag = "checkbox" )
433434
434435 def _get_radio_buttons (self , group_name ):
0 commit comments