Skip to content

Commit 700eaa6

Browse files
committed
Switched locator type over to TypeAlias
1 parent 9f5b9c7 commit 700eaa6

8 files changed

Lines changed: 118 additions & 110 deletions

File tree

src/SeleniumLibrary/keywords/element.py

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

src/SeleniumLibrary/keywords/formelement.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def submit_form(self, locator: Union[WebElement, None, str, List[Union[WebElemen
4141
element.submit()
4242

4343
@keyword
44-
def checkbox_should_be_selected(self, locator: Union[WebElement, str, List[Union[WebElement,str]]]):
44+
def checkbox_should_be_selected(self, locator: Locator):
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, List[Union
5555
)
5656

5757
@keyword
58-
def checkbox_should_not_be_selected(self, locator: Union[WebElement, str, List[Union[WebElement,str]]]):
58+
def checkbox_should_not_be_selected(self, locator: Locator):
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, List[U
6969
@keyword
7070
def page_should_contain_checkbox(
7171
self,
72-
locator: Union[WebElement, str, List[Union[WebElement,str]]],
72+
locator: Locator,
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, List[Union[WebElement,str]]],
89+
locator: Locator,
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, List[Union[WebElement,str]]]):
104+
def select_checkbox(self, locator: Locator):
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, List[Union[WebElement,
115115
element.click()
116116

117117
@keyword
118-
def unselect_checkbox(self, locator: Union[WebElement, str, List[Union[WebElement,str]]]):
118+
def unselect_checkbox(self, locator: Locator):
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, List[Union[WebElemen
131131
@keyword
132132
def page_should_contain_radio_button(
133133
self,
134-
locator: Union[WebElement, str, List[Union[WebElement,str]]],
134+
locator: Locator,
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, List[Union[WebElement,str]]],
152+
locator: Locator,
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, List[Union[WebElement,str]]], file_path: str):
216+
def choose_file(self, locator: Locator, 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, List[Union[WebElement,str]
240240

241241
@keyword
242242
def input_password(
243-
self, locator: Union[WebElement, str, List[Union[WebElement,str]]], password: str, clear: bool = True
243+
self, locator: Locator, 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, List[Union[WebElement,str]]], text: str, clear: bool = True
273+
self, locator: Locator, 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, List[Union[WebElement,str]]],
302+
locator: Locator,
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, List[Union[WebElement,str]]],
319+
locator: Locator,
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, List[Union[WebElement,str]]],
336+
locator: Locator,
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, List[Union[WebElement,str]]],
360+
locator: Locator,
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, List[Union[WebElement,str]]],
384+
locator: Locator,
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, List[Union[WebElement,str]]],
408+
locator: Locator,
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, List[Union[WebElement,str]]],
432+
locator: Locator,
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, List[Union[WebElement,str]]],
453+
locator: Locator,
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, List[Union[WebElement,str]]]):
472+
def _get_checkbox(self, locator: Locator):
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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
from selenium.webdriver.remote.webelement import WebElement
1919

2020
from SeleniumLibrary.base import LibraryComponent, keyword
21+
from SeleniumLibrary.utils.types import Locator
2122

2223

2324
class FrameKeywords(LibraryComponent):
2425
@keyword
25-
def select_frame(self, locator: Union[WebElement, str, List[Union[WebElement,str]]]):
26+
def select_frame(self, locator: Locator):
2627
"""Sets frame identified by ``locator`` as the current frame.
2728
2829
See the `Locating elements` section for details about the locator
@@ -82,7 +83,7 @@ def current_frame_should_not_contain(self, text: str, loglevel: str = "TRACE"):
8283

8384
@keyword
8485
def frame_should_contain(
85-
self, locator: Union[WebElement, str, List[Union[WebElement,str]]], text: str, loglevel: str = "TRACE"
86+
self, locator: Locator, text: str, loglevel: str = "TRACE"
8687
):
8788
"""Verifies that frame identified by ``locator`` contains ``text``.
8889
@@ -99,7 +100,7 @@ def frame_should_contain(
99100
)
100101
self.info(f"Frame '{locator}' contains text '{text}'.")
101102

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

src/SeleniumLibrary/keywords/screenshot.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
from SeleniumLibrary.base import LibraryComponent, keyword
2525
from SeleniumLibrary.utils.path_formatter import _format_path
26+
from SeleniumLibrary.utils.types import Locator
2627

2728
DEFAULT_FILENAME_PAGE = "selenium-screenshot-{index}.png"
2829
DEFAULT_FILENAME_ELEMENT = "selenium-element-screenshot-{index}.png"
@@ -146,7 +147,7 @@ def _capture_page_screen_to_log(self, return_val):
146147
@keyword
147148
def capture_element_screenshot(
148149
self,
149-
locator: Union[WebElement, str, List[Union[WebElement,str]]],
150+
locator: Locator,
150151
filename: str = DEFAULT_FILENAME_ELEMENT,
151152
) -> str:
152153
"""Captures a screenshot from the element identified by ``locator`` and embeds it into log file.

0 commit comments

Comments
 (0)