-1

How could I check to see if an element is not displayed. I would think it looks something like this.

if(element.is_not_displayed):
    doSomething()
else
    doSomethingElse()
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
stinkiepinkie
  • 105
  • 1
  • 9
  • Not present: https://stackoverflow.com/questions/42142054/assert-an-element-is-not-present-python-selenium, not displayed (but present): https://www.browserstack.com/guide/isdisplayed-method-in-selenium – Taco Verhagen Dec 04 '21 at 22:47

2 Answers2

0

To start with, there is no is_not_displayed attribute in Selenium.

To simulate a similar logic, instead of an if-else loop you may use a try-except{} loop inducing WebDriverWait for the invisibility_of_element() and you can use the following Locator Strategy:

try:        
    WebDriverWait(driver, 30).until(EC.invisibility_of_element(element))
    doSomething()
except TimeoutException:
    doSomethingElse()

Note : You have to add the following imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

You have to use until_not as shown bellow

WebDriverWait(driver, "time you want to wait".until_not(EC.presence_of_element_located((By.ID,"someID")))

Example:

WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID,"transpdiv-0"))) #here yout wait to the element appear

WebDriverWait(driver, 300).until_not(EC.presence_of_element_located((By.ID,"transpdiv-0"))) #here you wait the element disappear

Note: you have to add the same imports like undetect Selenium says:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException