1919Exceptions that may happen in all the webdriver code.
2020"""
2121
22+
2223class WebDriverException (Exception ):
2324 """
2425 Base webdriver exception.
@@ -38,6 +39,7 @@ def __str__(self):
3839 exception_msg += "Stacktrace:\n %s" % stacktrace
3940 return exception_msg
4041
42+
4143class ErrorInResponseException (WebDriverException ):
4244 """
4345 Thrown when an error has occurred on the server side.
@@ -49,52 +51,58 @@ def __init__(self, response, msg):
4951 WebDriverException .__init__ (self , msg )
5052 self .response = response
5153
54+
5255class InvalidSwitchToTargetException (WebDriverException ):
5356 """
5457 Thrown when frame or window target to be switched doesn't exist.
5558 """
5659 pass
5760
61+
5862class NoSuchFrameException (InvalidSwitchToTargetException ):
5963 """
6064 Thrown when frame target to be switched doesn't exist.
6165 """
6266 pass
6367
68+
6469class NoSuchWindowException (InvalidSwitchToTargetException ):
6570 """
6671 Thrown when window target to be switched doesn't exist.
6772
68- To find the current set of active window handles, you can get a list
73+ To find the current set of active window handles, you can get a list
6974 of the active window handles in the following way::
7075
7176 print driver.window_handles
7277
7378 """
7479 pass
7580
81+
7682class NoSuchElementException (WebDriverException ):
7783 """
7884 Thrown when element could not be found.
7985
8086 If you encounter this exception, you may want to check the following:
8187 * Check your selector used in your find_by...
8288 * Element may not yet be on the screen at the time of the find operation,
83- (webpage is still loading) see selenium.webdriver.support.wait.WebDriverWait()
89+ (webpage is still loading) see selenium.webdriver.support.wait.WebDriverWait()
8490 for how to write a wait wrapper to wait for an element to appear.
8591 """
8692 pass
8793
94+
8895class NoSuchAttributeException (WebDriverException ):
8996 """
9097 Thrown when the attribute of element could not be found.
9198
92- You may want to check if the attribute exists in the particular browser you are
93- testing against. Some browsers may have different property names for the same
99+ You may want to check if the attribute exists in the particular browser you are
100+ testing against. Some browsers may have different property names for the same
94101 property. (IE8's .innerText vs. Firefox .textContent)
95102 """
96103 pass
97104
105+
98106class StaleElementReferenceException (WebDriverException ):
99107 """
100108 Thrown when a reference to an element is now "stale".
@@ -103,26 +111,28 @@ class StaleElementReferenceException(WebDriverException):
103111
104112
105113 Possible causes of StaleElementReferenceException include, but not limited to:
106- * You are no longer on the same page, or the page may have refreshed since the element
114+ * You are no longer on the same page, or the page may have refreshed since the element
107115 was located.
108116 * The element may have been removed and re-added to the screen, since it was located.
109- Such as an element being relocated.
110- This can happen typically with a javascript framework when values are updated and the
117+ Such as an element being relocated.
118+ This can happen typically with a javascript framework when values are updated and the
111119 node is rebuilt.
112120 * Element may have been inside an iframe or another context which was refreshed.
113121 """
114122 pass
115123
116- class InvalidElementStateException (WebDriverException ):
124+
125+ class InvalidElementStateException (WebDriverException ):
117126 """
118127 """
119128 pass
120129
130+
121131class UnexpectedAlertPresentException (WebDriverException ):
122132 """
123133 Thrown when an unexpected alert is appeared.
124-
125- Usually raised when when an expected modal is blocking webdriver form executing any
134+
135+ Usually raised when when an expected modal is blocking webdriver form executing any
126136 more commands.
127137 """
128138 def __init__ (self , msg = None , screen = None , stacktrace = None , alert_text = None ):
@@ -132,70 +142,80 @@ def __init__(self, msg=None, screen=None, stacktrace=None, alert_text=None):
132142 def __str__ (self ):
133143 return "Alert Text: %s\n %s" % (self .alert_text , super (UnexpectedAlertPresentException , self ).__str__ ())
134144
145+
135146class NoAlertPresentException (WebDriverException ):
136147 """
137148 Thrown when switching to no presented alert.
138149
139- This can be caused by calling an operation on the Alert() class when an alert is
150+ This can be caused by calling an operation on the Alert() class when an alert is
140151 not yet on the screen.
141152 """
142153 pass
143154
155+
144156class ElementNotVisibleException (InvalidElementStateException ):
145157 """
146- Thrown when an element is present on the DOM, but
158+ Thrown when an element is present on the DOM, but
147159 it is not visible, and so is not able to be interacted with.
148160
149- Most commonly encountered when trying to click or read text
161+ Most commonly encountered when trying to click or read text
150162 of an element that is hidden from view.
151163 """
152164 pass
153165
166+
154167class ElementNotSelectableException (InvalidElementStateException ):
155168 """
156169 Thrown when trying to select an unselectable element.
157-
170+
158171 For example, selecting a 'script' element.
159172 """
160173 pass
161174
175+
162176class InvalidCookieDomainException (WebDriverException ):
163177 """
164178 Thrown when attempting to add a cookie under a different domain
165179 than the current URL.
166180 """
167181 pass
168182
183+
169184class UnableToSetCookieException (WebDriverException ):
170185 """
171186 Thrown when a driver fails to set a cookie.
172187 """
173188 pass
174189
190+
175191class RemoteDriverServerException (WebDriverException ):
176192 """
177193 """
178194 pass
179195
196+
180197class TimeoutException (WebDriverException ):
181198 """
182199 Thrown when a command does not complete in enough time.
183200 """
184201 pass
185202
203+
186204class MoveTargetOutOfBoundsException (WebDriverException ):
187205 """
188- Thrown when the target provided to the `ActionsChains` move()
206+ Thrown when the target provided to the `ActionsChains` move()
189207 method is invalid, i.e. out of document.
190208 """
191209 pass
192210
211+
193212class UnexpectedTagNameException (WebDriverException ):
194213 """
195214 Thrown when a support class did not get an expected web element.
196215 """
197216 pass
198217
218+
199219class InvalidSelectorException (NoSuchElementException ):
200220 """
201221 Thrown when the selector which is used to find an element does not return
@@ -206,13 +226,15 @@ class InvalidSelectorException(NoSuchElementException):
206226 """
207227 pass
208228
229+
209230class ImeNotAvailableException (WebDriverException ):
210231 """
211232 Thrown when IME support is not available. This exception is thrown for every IME-related
212233 method call if IME support is not available on the machine.
213234 """
214235 pass
215236
237+
216238class ImeActivationFailedException (WebDriverException ):
217239 """
218240 Thrown when activating an IME engine has failed.
0 commit comments