TestProject Forum

How to properly check if element is not displayed

Hi All,
Probably that will be a dumb question but I really need help.
Here is the test case:
Some element (E) is displayed while web page perform some action and when completed it disappear.
When element is disappeared it means action is successful, if it still displaying during some period of time - Fail

I’ve tried to do WebDriverWait(driver,time).until(EC.invisibility_of_element_located((By.CSS_SELECTOR,selector)))
But it throw exception even if no element is found and I got “Failed Test Case”

Please advice

Hello @vasily.serduk, thanks for reaching out.

You have a couple of ways to handle this,

The first one would be to catch the exception and continue the test.

The second would be to use the .is_displayed() method to check if the element is visible, it will return true if it is visible and false otherwise.

element = driver.find_element_by_name('name')
if element .is_displayed():
  print "Element found"
else:
  print "Element not found"