Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions py/selenium/common/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"""Exceptions that may happen in all the webdriver code."""

from collections.abc import Sequence
from typing import Optional
from typing import Any, Optional

SUPPORT_MSG = "For documentation on this error, please visit:"
ERROR_URL = "https://www.selenium.dev/documentation/webdriver/troubleshooting/errors"
Expand All @@ -27,7 +27,7 @@ class WebDriverException(Exception):
"""Base webdriver exception."""

def __init__(
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
) -> None:
super().__init__()
self.msg = msg
Expand Down Expand Up @@ -73,7 +73,7 @@ class NoSuchElementException(WebDriverException):
"""

def __init__(
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#nosuchelementexception"

Expand Down Expand Up @@ -112,7 +112,7 @@ class StaleElementReferenceException(WebDriverException):
"""

def __init__(
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#staleelementreferenceexception"

Expand All @@ -137,7 +137,7 @@ class UnexpectedAlertPresentException(WebDriverException):

def __init__(
self,
msg: Optional[str] = None,
msg: Optional[Any] = None,
screen: Optional[str] = None,
stacktrace: Optional[Sequence[str]] = None,
alert_text: Optional[str] = None,
Expand Down Expand Up @@ -166,7 +166,7 @@ class ElementNotVisibleException(InvalidElementStateException):
"""

def __init__(
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#elementnotvisibleexception"

Expand All @@ -178,7 +178,7 @@ class ElementNotInteractableException(InvalidElementStateException):
element will hit another element due to paint order."""

def __init__(
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#elementnotinteractableexception"

Expand Down Expand Up @@ -225,7 +225,7 @@ class InvalidSelectorException(WebDriverException):
"""

def __init__(
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#invalidselectorexception"

Expand Down Expand Up @@ -267,7 +267,7 @@ class ElementClickInterceptedException(WebDriverException):
clicked."""

def __init__(
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#elementclickinterceptedexception"

Expand All @@ -288,7 +288,7 @@ class InvalidSessionIdException(WebDriverException):
meaning the session either does not exist or that it's not active."""

def __init__(
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#invalidsessionidexception"

Expand All @@ -299,7 +299,7 @@ class SessionNotCreatedException(WebDriverException):
"""A new session could not be created."""

def __init__(
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}#sessionnotcreatedexception"

Expand All @@ -315,7 +315,7 @@ class NoSuchDriverException(WebDriverException):
"""Raised when driver is not specified and cannot be located."""

def __init__(
self, msg: Optional[str] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
self, msg: Optional[Any] = None, screen: Optional[str] = None, stacktrace: Optional[Sequence[str]] = None
) -> None:
with_support = f"{msg}; {SUPPORT_MSG} {ERROR_URL}/driver_location"

Expand Down
21 changes: 10 additions & 11 deletions py/selenium/webdriver/common/by.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

from typing import Literal, Optional

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


class By:
"""Set of supported locator strategies.
Expand Down Expand Up @@ -73,14 +75,14 @@ class By:
>>> element = driver.find_element(By.CSS_SELECTOR, "div.myElement")
"""

ID = "id"
XPATH = "xpath"
LINK_TEXT = "link text"
PARTIAL_LINK_TEXT = "partial link text"
NAME = "name"
TAG_NAME = "tag name"
CLASS_NAME = "class name"
CSS_SELECTOR = "css selector"
ID: ByType = "id"
XPATH: ByType = "xpath"
LINK_TEXT: ByType = "link text"
PARTIAL_LINK_TEXT: ByType = "partial link text"
NAME: ByType = "name"
TAG_NAME: ByType = "tag name"
CLASS_NAME: ByType = "class name"
CSS_SELECTOR: ByType = "css selector"

_custom_finders: dict[str, str] = {}

Expand All @@ -95,6 +97,3 @@ def get_finder(cls, name: str) -> Optional[str]:
@classmethod
def clear_custom_finders(cls) -> None:
cls._custom_finders.clear()


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