Reputation:
i got a function which looks something like this :
def resultCheck(self, message):
if self.driver.find_element_by_xpath("//*[contains(text(), '{}')]".format(message)):
return True
else: return False
And i'd like to assert that the element either exists or doesn't
self.assertFalse(self.resultCheck('Something'), 'Detailed search failed!')
The problem is that whenever i assertFalse it throws me element not found exception, how can i tackle this?
Upvotes: 0
Views: 1558
Reputation: 216
You should catch NoSuchElementException
to check if an element is visible:
def assertVisible(self, message):
try:
return self.driver.find_element_by_xpath("//*[contains(text(), '{}')]".format(message)):
except NoSuchElementException:
return False
return False
Upvotes: 1