Skip to content

Commit d6e2c41

Browse files
committed
Use pytest.raises in element finding tests
1 parent 6dab772 commit d6e2c41

File tree

2 files changed

+40
-143
lines changed

2 files changed

+40
-143
lines changed

py/test/selenium/webdriver/common/children_finding_tests.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@ def test_should_find_element_by_xpath(self):
3434
def test_should_not_find_element_by_xpath(self):
3535
self._load_page("nestedElements")
3636
element = self.driver.find_element_by_name("form2")
37-
try:
37+
with pytest.raises(NoSuchElementException):
3838
element.find_element_by_xpath("select/x")
39-
self.fail("Expected NoSuchElementException to have been thrown")
40-
except NoSuchElementException as e:
41-
pass
4239

4340
def test_finding_dot_slash_elements_on_element_by_xpath_should_find_not_top_level_elements(self):
4441
self._load_simple_page()
@@ -101,11 +98,8 @@ def test_should_find_element_by_id_when_multiple_matches_exist(self):
10198
def test_should_find_element_by_id_when_no_match_in_context(self):
10299
self._load_page("nestedElements")
103100
element = self.driver.find_element_by_id("test_id_div")
104-
try:
101+
with pytest.raises(NoSuchElementException):
105102
element.find_element_by_id("test_id_out")
106-
self.fail("Expected NoSuchElementException to have been thrown")
107-
except NoSuchElementException as e:
108-
pass
109103

110104
def test_should_find_element_by_link_text(self):
111105
self._load_page("nestedElements")

0 commit comments

Comments
 (0)