Skip to content

Commit 2d9cf16

Browse files
committed
[py] invalid selector exceptions are is not a no such element exception
different behaviors expected for find_elements
1 parent ca39d6f commit 2d9cf16

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

‎py/selenium/common/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class UnexpectedTagNameException(WebDriverException):
226226
pass
227227

228228

229-
class InvalidSelectorException(NoSuchElementException):
229+
class InvalidSelectorException(WebDriverException):
230230
"""
231231
Thrown when the selector which is used to find an element does not return
232232
a WebElement. Currently this only happens when the selector is an xpath

‎py/test/selenium/webdriver/common/driver_element_finding_tests.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,13 @@ def test_should_not_find_element_by_class_when_the_name_queried_is_shorter_than_
258258

259259
def test_finding_asingle_element_by_empty_class_name_should_throw(driver, pages):
260260
pages.load("xhtmlTest.html")
261-
with pytest.raises(NoSuchElementException):
261+
with pytest.raises(InvalidSelectorException):
262262
driver.find_element(By.CLASS_NAME, "")
263263

264264

265265
def test_finding_multiple_elements_by_empty_class_name_should_throw(driver, pages):
266266
pages.load("xhtmlTest.html")
267-
with pytest.raises(NoSuchElementException):
267+
with pytest.raises(InvalidSelectorException):
268268
driver.find_elements(By.CLASS_NAME, "")
269269

270270

@@ -276,13 +276,13 @@ def test_finding_asingle_element_by_compound_class_name_should_throw(driver, pag
276276

277277
def test_finding_asingle_element_by_invalid_class_name_should_throw(driver, pages):
278278
pages.load("xhtmlTest.html")
279-
with pytest.raises(NoSuchElementException):
279+
with pytest.raises(InvalidSelectorException):
280280
driver.find_element(By.CLASS_NAME, "!@#$%^&*")
281281

282282

283283
def test_finding_multiple_elements_by_invalid_class_name_should_throw(driver, pages):
284284
pages.load("xhtmlTest.html")
285-
with pytest.raises(NoSuchElementException):
285+
with pytest.raises(InvalidSelectorException):
286286
driver.find_elements(By.CLASS_NAME, "!@#$%^&*")
287287

288288
# By.xpath positive
@@ -477,25 +477,25 @@ def test_should_not_find_elements_by_css_selector_when_there_is_no_such_element(
477477

478478
def test_finding_asingle_element_by_empty_css_selector_should_throw(driver, pages):
479479
pages.load("xhtmlTest.html")
480-
with pytest.raises(NoSuchElementException):
480+
with pytest.raises(InvalidSelectorException):
481481
driver.find_element(By.CSS_SELECTOR, "")
482482

483483

484484
def test_finding_multiple_elements_by_empty_css_selector_should_throw(driver, pages):
485485
pages.load("xhtmlTest.html")
486-
with pytest.raises(NoSuchElementException):
486+
with pytest.raises(InvalidSelectorException):
487487
driver.find_elements(By.CSS_SELECTOR, "")
488488

489489

490490
def test_finding_asingle_element_by_invalid_css_selector_should_throw(driver, pages):
491491
pages.load("xhtmlTest.html")
492-
with pytest.raises(NoSuchElementException):
492+
with pytest.raises(InvalidSelectorException):
493493
driver.find_element(By.CSS_SELECTOR, "//a/b/c[@id='1']")
494494

495495

496496
def test_finding_multiple_elements_by_invalid_css_selector_should_throw(driver, pages):
497497
pages.load("xhtmlTest.html")
498-
with pytest.raises(NoSuchElementException):
498+
with pytest.raises(InvalidSelectorException):
499499
driver.find_elements(By.CSS_SELECTOR, "//a/b/c[@id='1']")
500500

501501
# By.link_Text positive

0 commit comments

Comments
 (0)