17
17
18
18
import re
19
19
20
- from selenium .common .exceptions import NoSuchElementException
20
+ from selenium .common .exceptions import NoSuchElementException , InvalidSelectorException
21
21
from selenium .common .exceptions import NoSuchFrameException
22
22
from selenium .common .exceptions import StaleElementReferenceException
23
23
from selenium .common .exceptions import WebDriverException
@@ -123,6 +123,8 @@ def visibility_of_element_located(locator):
123
123
def _predicate (driver ):
124
124
try :
125
125
return _element_if_visible (driver .find_element (* locator ))
126
+ except InvalidSelectorException as e :
127
+ raise e
126
128
except StaleElementReferenceException :
127
129
return False
128
130
@@ -188,6 +190,8 @@ def _predicate(driver):
188
190
if _element_if_visible (element , visibility = False ):
189
191
return False
190
192
return elements
193
+ except InvalidSelectorException as e :
194
+ raise e
191
195
except StaleElementReferenceException :
192
196
return False
193
197
@@ -204,6 +208,8 @@ def _predicate(driver):
204
208
try :
205
209
element_text = driver .find_element (* locator ).text
206
210
return text_ in element_text
211
+ except InvalidSelectorException as e :
212
+ raise e
207
213
except StaleElementReferenceException :
208
214
return False
209
215
@@ -220,6 +226,8 @@ def _predicate(driver):
220
226
try :
221
227
element_text = driver .find_element (* locator ).get_attribute ("value" )
222
228
return text_ in element_text
229
+ except InvalidSelectorException as e :
230
+ raise e
223
231
except StaleElementReferenceException :
224
232
return False
225
233
@@ -239,6 +247,8 @@ def _predicate(driver):
239
247
else :
240
248
driver .switch_to .frame (locator )
241
249
return True
250
+ except InvalidSelectorException as e :
251
+ raise e
242
252
except NoSuchFrameException :
243
253
return False
244
254
@@ -258,6 +268,8 @@ def _predicate(driver):
258
268
if not isinstance (target , WebElement ):
259
269
target = driver .find_element (* target )
260
270
return _element_if_visible (target , False )
271
+ except InvalidSelectorException as e :
272
+ raise e
261
273
except (NoSuchElementException , StaleElementReferenceException ):
262
274
# In the case of NoSuchElement, returns true because the element is
263
275
# not present in DOM. The try block checks if the element is present
@@ -312,6 +324,8 @@ def _predicate(_):
312
324
# Calling any method forces a staleness check
313
325
element .is_enabled ()
314
326
return False
327
+ except InvalidSelectorException as e :
328
+ raise e
315
329
except StaleElementReferenceException :
316
330
return True
317
331
@@ -362,6 +376,8 @@ def _predicate(driver):
362
376
try :
363
377
element = driver .find_element (* locator )
364
378
return element .is_selected () == is_selected
379
+ except InvalidSelectorException as e :
380
+ raise e
365
381
except StaleElementReferenceException :
366
382
return False
367
383
@@ -407,6 +423,8 @@ def _predicate(driver):
407
423
try :
408
424
element_attribute = driver .find_element (* locator ).get_attribute (attribute_ )
409
425
return element_attribute is not None
426
+ except InvalidSelectorException as e :
427
+ raise e
410
428
except StaleElementReferenceException :
411
429
return False
412
430
0 commit comments