1717"""Exceptions that may happen in all the webdriver code."""
1818
1919from collections .abc import Sequence
20- from typing import Any
20+ from typing import Any , Optional , Union
2121
2222SUPPORT_MSG = "For documentation on this error, please visit:"
2323ERROR_URL = "https://www.selenium.dev/documentation/webdriver/troubleshooting/errors"
@@ -27,7 +27,10 @@ class WebDriverException(Exception):
2727 """Base webdriver exception."""
2828
2929 def __init__ (
30- self , msg : Any | None = None , screen : str | None = None , stacktrace : Sequence [str ] | None = None
30+ self ,
31+ msg : Optional [Any ] = None ,
32+ screen : Optional [str ] = None ,
33+ stacktrace : Optional [Sequence [str ]] = None ,
3134 ) -> None :
3235 super ().__init__ ()
3336 self .msg = msg
@@ -73,7 +76,10 @@ class NoSuchElementException(WebDriverException):
7376 """
7477
7578 def __init__ (
76- self , msg : Any | None = None , screen : str | None = None , stacktrace : Sequence [str ] | None = None
79+ self ,
80+ msg : Optional [Any ] = None ,
81+ screen : Optional [str ] = None ,
82+ stacktrace : Optional [Sequence [str ]] = None ,
7783 ) -> None :
7884 with_support = f"{ msg } ; { SUPPORT_MSG } { ERROR_URL } #nosuchelementexception"
7985
@@ -111,9 +117,14 @@ class StaleElementReferenceException(WebDriverException):
111117 """
112118
113119 def __init__ (
114- self , msg : Any | None = None , screen : str | None = None , stacktrace : Sequence [str ] | None = None
120+ self ,
121+ msg : Optional [Any ] = None ,
122+ screen : Optional [str ] = None ,
123+ stacktrace : Optional [Sequence [str ]] = None ,
115124 ) -> None :
116- with_support = f"{ msg } ; { SUPPORT_MSG } { ERROR_URL } #staleelementreferenceexception"
125+ with_support = (
126+ f"{ msg } ; { SUPPORT_MSG } { ERROR_URL } #staleelementreferenceexception"
127+ )
117128
118129 super ().__init__ (with_support , screen , stacktrace )
119130
@@ -134,10 +145,10 @@ class UnexpectedAlertPresentException(WebDriverException):
134145
135146 def __init__ (
136147 self ,
137- msg : Any | None = None ,
138- screen : str | None = None ,
139- stacktrace : Sequence [str ] | None = None ,
140- alert_text : str | None = None ,
148+ msg : Optional [ Any ] = None ,
149+ screen : Optional [ str ] = None ,
150+ stacktrace : Optional [ Sequence [str ]] = None ,
151+ alert_text : Optional [ str ] = None ,
141152 ) -> None :
142153 super ().__init__ (msg , screen , stacktrace )
143154 self .alert_text = alert_text
@@ -161,7 +172,10 @@ class ElementNotVisibleException(InvalidElementStateException):
161172 """
162173
163174 def __init__ (
164- self , msg : Any | None = None , screen : str | None = None , stacktrace : Sequence [str ] | None = None
175+ self ,
176+ msg : Optional [Any ] = None ,
177+ screen : Optional [str ] = None ,
178+ stacktrace : Optional [Sequence [str ]] = None ,
165179 ) -> None :
166180 with_support = f"{ msg } ; { SUPPORT_MSG } { ERROR_URL } #elementnotvisibleexception"
167181
@@ -172,9 +186,14 @@ class ElementNotInteractableException(InvalidElementStateException):
172186 """Thrown when element interactions will hit another element due to paint order."""
173187
174188 def __init__ (
175- self , msg : Any | None = None , screen : str | None = None , stacktrace : Sequence [str ] | None = None
189+ self ,
190+ msg : Optional [Any ] = None ,
191+ screen : Optional [str ] = None ,
192+ stacktrace : Optional [Sequence [str ]] = None ,
176193 ) -> None :
177- with_support = f"{ msg } ; { SUPPORT_MSG } { ERROR_URL } #elementnotinteractableexception"
194+ with_support = (
195+ f"{ msg } ; { SUPPORT_MSG } { ERROR_URL } #elementnotinteractableexception"
196+ )
178197
179198 super ().__init__ (with_support , screen , stacktrace )
180199
@@ -213,7 +232,10 @@ class InvalidSelectorException(WebDriverException):
213232 """
214233
215234 def __init__ (
216- self , msg : Any | None = None , screen : str | None = None , stacktrace : Sequence [str ] | None = None
235+ self ,
236+ msg : Optional [Any ] = None ,
237+ screen : Optional [str ] = None ,
238+ stacktrace : Optional [Sequence [str ]] = None ,
217239 ) -> None :
218240 with_support = f"{ msg } ; { SUPPORT_MSG } { ERROR_URL } #invalidselectorexception"
219241
@@ -252,9 +274,14 @@ class ElementClickInterceptedException(WebDriverException):
252274 """Thrown when element click fails because another element obscures it."""
253275
254276 def __init__ (
255- self , msg : Any | None = None , screen : str | None = None , stacktrace : Sequence [str ] | None = None
277+ self ,
278+ msg : Optional [Any ] = None ,
279+ screen : Optional [str ] = None ,
280+ stacktrace : Optional [Sequence [str ]] = None ,
256281 ) -> None :
257- with_support = f"{ msg } ; { SUPPORT_MSG } { ERROR_URL } #elementclickinterceptedexception"
282+ with_support = (
283+ f"{ msg } ; { SUPPORT_MSG } { ERROR_URL } #elementclickinterceptedexception"
284+ )
258285
259286 super ().__init__ (with_support , screen , stacktrace )
260287
@@ -271,7 +298,10 @@ class InvalidSessionIdException(WebDriverException):
271298 """Thrown when the given session id is not in the list of active sessions."""
272299
273300 def __init__ (
274- self , msg : Any | None = None , screen : str | None = None , stacktrace : Sequence [str ] | None = None
301+ self ,
302+ msg : Optional [Any ] = None ,
303+ screen : Optional [str ] = None ,
304+ stacktrace : Optional [Sequence [str ]] = None ,
275305 ) -> None :
276306 with_support = f"{ msg } ; { SUPPORT_MSG } { ERROR_URL } #invalidsessionidexception"
277307
@@ -282,7 +312,10 @@ class SessionNotCreatedException(WebDriverException):
282312 """A new session could not be created."""
283313
284314 def __init__ (
285- self , msg : Any | None = None , screen : str | None = None , stacktrace : Sequence [str ] | None = None
315+ self ,
316+ msg : Optional [Any ] = None ,
317+ screen : Optional [str ] = None ,
318+ stacktrace : Optional [Sequence [str ]] = None ,
286319 ) -> None :
287320 with_support = f"{ msg } ; { SUPPORT_MSG } { ERROR_URL } #sessionnotcreatedexception"
288321
@@ -297,7 +330,10 @@ class NoSuchDriverException(WebDriverException):
297330 """Raised when driver is not specified and cannot be located."""
298331
299332 def __init__ (
300- self , msg : Any | None = None , screen : str | None = None , stacktrace : Sequence [str ] | None = None
333+ self ,
334+ msg : Optional [Any ] = None ,
335+ screen : Optional [str ] = None ,
336+ stacktrace : Optional [Sequence [str ]] = None ,
301337 ) -> None :
302338 with_support = f"{ msg } ; { SUPPORT_MSG } { ERROR_URL } /driver_location"
303339
0 commit comments