Skip to content

Commit 4bbd2bd

Browse files
[py] Add type hints to relative by code
1 parent f07ffac commit 4bbd2bd

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

py/selenium/webdriver/support/relative_locator.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,52 @@
1616
# under the License.
1717

1818

19+
from typing import Dict, List, Union
1920
from selenium.common.exceptions import WebDriverException
21+
from selenium.webdriver.remote.webelement import WebElement
2022

2123

22-
def with_tag_name(tag_name):
24+
def with_tag_name(tag_name: str):
2325
if not tag_name:
2426
raise WebDriverException("tag_name can not be null")
2527
return RelativeBy({"css selector": tag_name})
2628

2729

2830
class RelativeBy(object):
2931

30-
def __init__(self, root=None, filters=None):
32+
def __init__(self, root: Dict = None, filters: List = None):
3133
self.root = root
3234
self.filters = filters or []
3335

34-
def above(self, element_or_locator=None):
36+
def above(self, element_or_locator: Union[WebElement, Dict] = None):
3537
if not element_or_locator:
3638
raise WebDriverException("Element or locator must be given when calling above method")
3739

3840
self.filters.append({"kind": "above", "args": [element_or_locator]})
3941
return self
4042

41-
def below(self, element_or_locator=None):
43+
def below(self, element_or_locator: Union[WebElement, Dict] = None):
4244
if not element_or_locator:
4345
raise WebDriverException("Element or locator must be given when calling above method")
4446

4547
self.filters.append({"kind": "below", "args": [element_or_locator]})
4648
return self
4749

48-
def to_left_of(self, element_or_locator=None):
50+
def to_left_of(self, element_or_locator: Union[WebElement, Dict] = None):
4951
if not element_or_locator:
5052
raise WebDriverException("Element or locator must be given when calling above method")
5153

5254
self.filters.append({"kind": "left", "args": [element_or_locator]})
5355
return self
5456

55-
def to_right_of(self, element_or_locator):
57+
def to_right_of(self, element_or_locator: Union[WebElement, Dict] = None):
5658
if not element_or_locator:
5759
raise WebDriverException("Element or locator must be given when calling above method")
5860

5961
self.filters.append({"kind": "right", "args": [element_or_locator]})
6062
return self
6163

62-
def near(self, element_or_locator_distance=None):
64+
def near(self, element_or_locator_distance: Union[WebElement, Dict, int] = None):
6365
if not element_or_locator_distance:
6466
raise WebDriverException("Element or locator or distance must be given when calling above method")
6567

0 commit comments

Comments
 (0)