Skip to content

Commit 00f7f17

Browse files
committed
Adding the type annotation for the cascading locators to keywords
1 parent ce9d0ec commit 00f7f17

File tree

7 files changed

+112
-112
lines changed

7 files changed

+112
-112
lines changed

src/SeleniumLibrary/keywords/element.py

Lines changed: 48 additions & 48 deletions
Large diffs are not rendered by default.

src/SeleniumLibrary/keywords/formelement.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# limitations under the License.
1616

1717
import os
18-
from typing import Optional, Union
18+
from typing import Optional, Union, List
1919

2020
from robot.libraries.BuiltIn import BuiltIn
2121
from selenium.webdriver.remote.webelement import WebElement
@@ -26,7 +26,7 @@
2626

2727
class FormElementKeywords(LibraryComponent):
2828
@keyword
29-
def submit_form(self, locator: Union[WebElement, None, str] = None):
29+
def submit_form(self, locator: Union[WebElement, None, str, List[Union[WebElement,str]]] = None):
3030
"""Submits a form identified by ``locator``.
3131
3232
If ``locator`` is not given, first form on the page is submitted.
@@ -41,7 +41,7 @@ def submit_form(self, locator: Union[WebElement, None, str] = None):
4141
element.submit()
4242

4343
@keyword
44-
def checkbox_should_be_selected(self, locator: Union[WebElement, str]):
44+
def checkbox_should_be_selected(self, locator: Union[WebElement, str, List[Union[WebElement,str]]]):
4545
"""Verifies checkbox ``locator`` is selected/checked.
4646
4747
See the `Locating elements` section for details about the locator
@@ -55,7 +55,7 @@ def checkbox_should_be_selected(self, locator: Union[WebElement, str]):
5555
)
5656

5757
@keyword
58-
def checkbox_should_not_be_selected(self, locator: Union[WebElement, str]):
58+
def checkbox_should_not_be_selected(self, locator: Union[WebElement, str, List[Union[WebElement,str]]]):
5959
"""Verifies checkbox ``locator`` is not selected/checked.
6060
6161
See the `Locating elements` section for details about the locator
@@ -69,7 +69,7 @@ def checkbox_should_not_be_selected(self, locator: Union[WebElement, str]):
6969
@keyword
7070
def page_should_contain_checkbox(
7171
self,
72-
locator: Union[WebElement, str],
72+
locator: Union[WebElement, str, List[Union[WebElement,str]]],
7373
message: Optional[str] = None,
7474
loglevel: str = "TRACE",
7575
):
@@ -86,7 +86,7 @@ def page_should_contain_checkbox(
8686
@keyword
8787
def page_should_not_contain_checkbox(
8888
self,
89-
locator: Union[WebElement, str],
89+
locator: Union[WebElement, str, List[Union[WebElement,str]]],
9090
message: Optional[str] = None,
9191
loglevel: str = "TRACE",
9292
):
@@ -101,7 +101,7 @@ def page_should_not_contain_checkbox(
101101
self.assert_page_not_contains(locator, "checkbox", message, loglevel)
102102

103103
@keyword
104-
def select_checkbox(self, locator: Union[WebElement, str]):
104+
def select_checkbox(self, locator: Union[WebElement, str, List[Union[WebElement,str]]]):
105105
"""Selects the checkbox identified by ``locator``.
106106
107107
Does nothing if checkbox is already selected.
@@ -115,7 +115,7 @@ def select_checkbox(self, locator: Union[WebElement, str]):
115115
element.click()
116116

117117
@keyword
118-
def unselect_checkbox(self, locator: Union[WebElement, str]):
118+
def unselect_checkbox(self, locator: Union[WebElement, str, List[Union[WebElement,str]]]):
119119
"""Removes the selection of checkbox identified by ``locator``.
120120
121121
Does nothing if the checkbox is not selected.
@@ -131,7 +131,7 @@ def unselect_checkbox(self, locator: Union[WebElement, str]):
131131
@keyword
132132
def page_should_contain_radio_button(
133133
self,
134-
locator: Union[WebElement, str],
134+
locator: Union[WebElement, str, List[Union[WebElement,str]]],
135135
message: Optional[str] = None,
136136
loglevel: str = "TRACE",
137137
):
@@ -149,7 +149,7 @@ def page_should_contain_radio_button(
149149
@keyword
150150
def page_should_not_contain_radio_button(
151151
self,
152-
locator: Union[WebElement, str],
152+
locator: Union[WebElement, str, List[Union[WebElement,str]]],
153153
message: Optional[str] = None,
154154
loglevel: str = "TRACE",
155155
):
@@ -213,7 +213,7 @@ def select_radio_button(self, group_name: str, value: str):
213213
element.click()
214214

215215
@keyword
216-
def choose_file(self, locator: Union[WebElement, str], file_path: str):
216+
def choose_file(self, locator: Union[WebElement, str, List[Union[WebElement,str]]], file_path: str):
217217
"""Inputs the ``file_path`` into the file input field ``locator``.
218218
219219
This keyword is most often used to input files into upload forms.
@@ -240,7 +240,7 @@ def choose_file(self, locator: Union[WebElement, str], file_path: str):
240240

241241
@keyword
242242
def input_password(
243-
self, locator: Union[WebElement, str], password: str, clear: bool = True
243+
self, locator: Union[WebElement, str, List[Union[WebElement,str]]], password: str, clear: bool = True
244244
):
245245
"""Types the given password into the text field identified by ``locator``.
246246
@@ -270,7 +270,7 @@ def input_password(
270270

271271
@keyword
272272
def input_text(
273-
self, locator: Union[WebElement, str], text: str, clear: bool = True
273+
self, locator: Union[WebElement, str, List[Union[WebElement,str]]], text: str, clear: bool = True
274274
):
275275
"""Types the given ``text`` into the text field identified by ``locator``.
276276
@@ -299,7 +299,7 @@ def input_text(
299299
@keyword
300300
def page_should_contain_textfield(
301301
self,
302-
locator: Union[WebElement, str],
302+
locator: Union[WebElement, str, List[Union[WebElement,str]]],
303303
message: Optional[str] = None,
304304
loglevel: str = "TRACE",
305305
):
@@ -316,7 +316,7 @@ def page_should_contain_textfield(
316316
@keyword
317317
def page_should_not_contain_textfield(
318318
self,
319-
locator: Union[WebElement, str],
319+
locator: Union[WebElement, str, List[Union[WebElement,str]]],
320320
message: Optional[str] = None,
321321
loglevel: str = "TRACE",
322322
):
@@ -333,7 +333,7 @@ def page_should_not_contain_textfield(
333333
@keyword
334334
def textfield_should_contain(
335335
self,
336-
locator: Union[WebElement, str],
336+
locator: Union[WebElement, str, List[Union[WebElement,str]]],
337337
expected: str,
338338
message: Optional[str] = None,
339339
):
@@ -357,7 +357,7 @@ def textfield_should_contain(
357357
@keyword
358358
def textfield_value_should_be(
359359
self,
360-
locator: Union[WebElement, str],
360+
locator: Union[WebElement, str, List[Union[WebElement,str]]],
361361
expected: str,
362362
message: Optional[str] = None,
363363
):
@@ -381,7 +381,7 @@ def textfield_value_should_be(
381381
@keyword
382382
def textarea_should_contain(
383383
self,
384-
locator: Union[WebElement, str],
384+
locator: Union[WebElement, str, List[Union[WebElement,str]]],
385385
expected: str,
386386
message: Optional[str] = None,
387387
):
@@ -405,7 +405,7 @@ def textarea_should_contain(
405405
@keyword
406406
def textarea_value_should_be(
407407
self,
408-
locator: Union[WebElement, str],
408+
locator: Union[WebElement, str, List[Union[WebElement,str]]],
409409
expected: str,
410410
message: Optional[str] = None,
411411
):
@@ -429,7 +429,7 @@ def textarea_value_should_be(
429429
@keyword
430430
def page_should_contain_button(
431431
self,
432-
locator: Union[WebElement, str],
432+
locator: Union[WebElement, str, List[Union[WebElement,str]]],
433433
message: Optional[str] = None,
434434
loglevel: str = "TRACE",
435435
):
@@ -450,7 +450,7 @@ def page_should_contain_button(
450450
@keyword
451451
def page_should_not_contain_button(
452452
self,
453-
locator: Union[WebElement, str],
453+
locator: Union[WebElement, str, List[Union[WebElement,str]]],
454454
message: Optional[str] = None,
455455
loglevel: str = "TRACE",
456456
):
@@ -469,7 +469,7 @@ def page_should_not_contain_button(
469469
def _get_value(self, locator, tag):
470470
return self.find_element(locator, tag).get_attribute("value")
471471

472-
def _get_checkbox(self, locator: Union[WebElement, str]):
472+
def _get_checkbox(self, locator: Union[WebElement, str, List[Union[WebElement,str]]]):
473473
return self.find_element(locator, tag="checkbox")
474474

475475
def _get_radio_buttons(self, group_name):

src/SeleniumLibrary/keywords/frames.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
16-
from typing import Union
16+
from typing import Union, List
1717

1818
from selenium.webdriver.remote.webelement import WebElement
1919

@@ -22,7 +22,7 @@
2222

2323
class FrameKeywords(LibraryComponent):
2424
@keyword
25-
def select_frame(self, locator: Union[WebElement, str]):
25+
def select_frame(self, locator: Union[WebElement, str, List[Union[WebElement,str]]]):
2626
"""Sets frame identified by ``locator`` as the current frame.
2727
2828
See the `Locating elements` section for details about the locator
@@ -82,7 +82,7 @@ def current_frame_should_not_contain(self, text: str, loglevel: str = "TRACE"):
8282

8383
@keyword
8484
def frame_should_contain(
85-
self, locator: Union[WebElement, str], text: str, loglevel: str = "TRACE"
85+
self, locator: Union[WebElement, str, List[Union[WebElement,str]]], text: str, loglevel: str = "TRACE"
8686
):
8787
"""Verifies that frame identified by ``locator`` contains ``text``.
8888
@@ -99,7 +99,7 @@ def frame_should_contain(
9999
)
100100
self.info(f"Frame '{locator}' contains text '{text}'.")
101101

102-
def _frame_contains(self, locator: Union[WebElement, str], text: str):
102+
def _frame_contains(self, locator: Union[WebElement, str, List[Union[WebElement,str]]], text: str):
103103
element = self.find_element(locator)
104104
self.driver.switch_to.frame(element)
105105
self.info(f"Searching for text from frame '{locator}'.")

src/SeleniumLibrary/keywords/screenshot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
import os
17-
from typing import Optional, Union
17+
from typing import Optional, Union, List
1818
from base64 import b64decode
1919

2020
from robot.utils import get_link_path
@@ -146,7 +146,7 @@ def _capture_page_screen_to_log(self, return_val):
146146
@keyword
147147
def capture_element_screenshot(
148148
self,
149-
locator: Union[WebElement, str],
149+
locator: Union[WebElement, str, List[Union[WebElement,str]]],
150150
filename: str = DEFAULT_FILENAME_ELEMENT,
151151
) -> str:
152152
"""Captures a screenshot from the element identified by ``locator`` and embeds it into log file.

0 commit comments

Comments
 (0)