Skip to content

Commit 06d3045

Browse files
moved the bytype at module level, fixed the imports, reverted the return type
1 parent 673582d commit 06d3045

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

py/selenium/webdriver/common/by.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from typing import Literal, Optional
2020

21+
ByType = Literal["id", "xpath", "link text", "partial link text", "name", "tag name", "class name", "css selector"]
2122

2223
class By:
2324
"""Set of supported locator strategies.
@@ -73,14 +74,15 @@ class By:
7374
>>> element = driver.find_element(By.CSS_SELECTOR, "div.myElement")
7475
"""
7576

76-
ID = "id"
77-
XPATH = "xpath"
78-
LINK_TEXT = "link text"
79-
PARTIAL_LINK_TEXT = "partial link text"
80-
NAME = "name"
81-
TAG_NAME = "tag name"
82-
CLASS_NAME = "class name"
83-
CSS_SELECTOR = "css selector"
77+
78+
ID: ByType = "id"
79+
XPATH: ByType = "xpath"
80+
LINK_TEXT: ByType = "link text"
81+
PARTIAL_LINK_TEXT: ByType = "partial link text"
82+
NAME: ByType = "name"
83+
TAG_NAME: ByType = "tag name"
84+
CLASS_NAME: ByType = "class name"
85+
CSS_SELECTOR: ByType = "css selector"
8486

8587
_custom_finders: dict[str, str] = {}
8688

@@ -97,4 +99,4 @@ def clear_custom_finders(cls) -> None:
9799
cls._custom_finders.clear()
98100

99101

100-
ByType = Literal["id", "xpath", "link text", "partial link text", "name", "tag name", "class name", "css selector"]
102+

py/selenium/webdriver/support/relative_locator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
from selenium.common.exceptions import WebDriverException
2121
from selenium.webdriver.common.by import ByType
22+
from selenium.webdriver.common.by import By
2223
from selenium.webdriver.remote.webelement import WebElement
2324

2425

@@ -48,8 +49,7 @@ def with_tag_name(tag_name: str) -> "RelativeBy":
4849
warnings.warn("This method is deprecated and may be removed in future versions. Please use `locate_with` instead.")
4950
if not tag_name:
5051
raise WebDriverException("tag_name can not be null")
51-
return RelativeBy({"css selector": tag_name})
52-
52+
return RelativeBy({By.CSS_SELECTOR: tag_name})
5353

5454
def locate_with(by: ByType, using: str) -> "RelativeBy":
5555
"""Start searching for relative objects your search criteria with By.

0 commit comments

Comments
 (0)