15
15
# limitations under the License.
16
16
17
17
import os
18
- from typing import Optional
18
+ from typing import Optional , Union
19
19
20
20
from robot .libraries .BuiltIn import BuiltIn
21
+ from selenium .webdriver .remote .webelement import WebElement
21
22
22
23
from SeleniumLibrary .base import LibraryComponent , keyword
23
24
from SeleniumLibrary .errors import ElementNotFound
24
25
25
26
26
27
class FormElementKeywords (LibraryComponent ):
27
28
@keyword
28
- def submit_form (self , locator : Optional [ str ] = None ):
29
+ def submit_form (self , locator : Union [ WebElement , None , str ] = None ):
29
30
"""Submits a form identified by ``locator``.
30
31
31
32
If ``locator`` is not given, first form on the page is submitted.
@@ -40,7 +41,7 @@ def submit_form(self, locator: Optional[str] = None):
40
41
element .submit ()
41
42
42
43
@keyword
43
- def checkbox_should_be_selected (self , locator : str ):
44
+ def checkbox_should_be_selected (self , locator : Union [ WebElement , str ] ):
44
45
"""Verifies checkbox ``locator`` is selected/checked.
45
46
46
47
See the `Locating elements` section for details about the locator
@@ -54,7 +55,7 @@ def checkbox_should_be_selected(self, locator: str):
54
55
)
55
56
56
57
@keyword
57
- def checkbox_should_not_be_selected (self , locator : str ):
58
+ def checkbox_should_not_be_selected (self , locator : Union [ WebElement , str ] ):
58
59
"""Verifies checkbox ``locator`` is not selected/checked.
59
60
60
61
See the `Locating elements` section for details about the locator
@@ -67,7 +68,7 @@ def checkbox_should_not_be_selected(self, locator: str):
67
68
68
69
@keyword
69
70
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"
71
72
):
72
73
"""Verifies checkbox ``locator`` is found from the current page.
73
74
@@ -81,7 +82,7 @@ def page_should_contain_checkbox(
81
82
82
83
@keyword
83
84
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"
85
86
):
86
87
"""Verifies checkbox ``locator`` is not found from the current page.
87
88
@@ -94,7 +95,7 @@ def page_should_not_contain_checkbox(
94
95
self .assert_page_not_contains (locator , "checkbox" , message , loglevel )
95
96
96
97
@keyword
97
- def select_checkbox (self , locator : str ):
98
+ def select_checkbox (self , locator : Union [ WebElement , str ] ):
98
99
"""Selects the checkbox identified by ``locator``.
99
100
100
101
Does nothing if checkbox is already selected.
@@ -108,7 +109,7 @@ def select_checkbox(self, locator: str):
108
109
element .click ()
109
110
110
111
@keyword
111
- def unselect_checkbox (self , locator : str ):
112
+ def unselect_checkbox (self , locator : Union [ WebElement , str ] ):
112
113
"""Removes the selection of checkbox identified by ``locator``.
113
114
114
115
Does nothing if the checkbox is not selected.
@@ -123,7 +124,7 @@ def unselect_checkbox(self, locator: str):
123
124
124
125
@keyword
125
126
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"
127
128
):
128
129
"""Verifies radio button ``locator`` is found from current page.
129
130
@@ -138,7 +139,7 @@ def page_should_contain_radio_button(
138
139
139
140
@keyword
140
141
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"
142
143
):
143
144
"""Verifies radio button ``locator`` is not found from current page.
144
145
@@ -200,7 +201,7 @@ def select_radio_button(self, group_name: str, value: str):
200
201
element .click ()
201
202
202
203
@keyword
203
- def choose_file (self , locator : str , file_path : str ):
204
+ def choose_file (self , locator : Union [ WebElement , str ] , file_path : str ):
204
205
"""Inputs the ``file_path`` into the file input field ``locator``.
205
206
206
207
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):
226
227
self .ctx ._running_keyword = None
227
228
228
229
@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 ):
230
231
"""Types the given password into the text field identified by ``locator``.
231
232
232
233
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):
254
255
self ._input_text_into_text_field (locator , password , clear , disable_log = True )
255
256
256
257
@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 ):
258
259
"""Types the given ``text`` into the text field identified by ``locator``.
259
260
260
261
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):
281
282
282
283
@keyword
283
284
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"
285
286
):
286
287
"""Verifies text field ``locator`` is found from current page.
287
288
@@ -295,7 +296,7 @@ def page_should_contain_textfield(
295
296
296
297
@keyword
297
298
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"
299
300
):
300
301
"""Verifies text field ``locator`` is not found from current page.
301
302
@@ -309,7 +310,7 @@ def page_should_not_contain_textfield(
309
310
310
311
@keyword
311
312
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
313
314
):
314
315
"""Verifies text field ``locator`` contains text ``expected``.
315
316
@@ -330,7 +331,7 @@ def textfield_should_contain(
330
331
331
332
@keyword
332
333
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
334
335
):
335
336
"""Verifies text field ``locator`` has exactly text ``expected``.
336
337
@@ -351,7 +352,7 @@ def textfield_value_should_be(
351
352
352
353
@keyword
353
354
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
355
356
):
356
357
"""Verifies text area ``locator`` contains text ``expected``.
357
358
@@ -372,7 +373,7 @@ def textarea_should_contain(
372
373
373
374
@keyword
374
375
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
376
377
):
377
378
"""Verifies text area ``locator`` has exactly text ``expected``.
378
379
@@ -393,7 +394,7 @@ def textarea_value_should_be(
393
394
394
395
@keyword
395
396
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"
397
398
):
398
399
"""Verifies button ``locator`` is found from current page.
399
400
@@ -411,7 +412,7 @@ def page_should_contain_button(
411
412
412
413
@keyword
413
414
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"
415
416
):
416
417
"""Verifies button ``locator`` is not found from current page.
417
418
@@ -428,7 +429,7 @@ def page_should_not_contain_button(
428
429
def _get_value (self , locator , tag ):
429
430
return self .find_element (locator , tag ).get_attribute ("value" )
430
431
431
- def _get_checkbox (self , locator ):
432
+ def _get_checkbox (self , locator : Union [ WebElement , str ] ):
432
433
return self .find_element (locator , tag = "checkbox" )
433
434
434
435
def _get_radio_buttons (self , group_name ):
0 commit comments