Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wait until element is not present

I'm using selenium in Python 2.7 and I have this code, but I'm looking for a more efficient way to do this:

while True:
    try:
        element = WebDriverWait(driver, 10).until(
            EC.presence_of_element_located((By.ID, 'button'))
        )   
    except:
        break
like image 208
User Avatar asked Sep 22 '15 12:09

User


People also ask

How wait until element is not present in Selenium?

To check if an element no longer exists on the page, we can take the help of the expected condition invisibilityOfElementLocated. To implement explicit wait conditions, we have to take help of the WebDriverWait and ExpectedCondition class.

How do you use wait until an element is visible?

Selenium: Waiting Until the Element Is Visiblevar wait = new WebDriverWait(driver, TimeSpan. FromSeconds(20)); As you can see, we give the WebDriverWait object two parameters: the driver itself and a TimeSpan object that represents the timeout for trying to locate the element.

Is implicit wait deprecated?

implicitlyWait. Deprecated. Use implicitlyWait(Duration) Specifies the amount of time the driver should wait when searching for an element if it is not immediately present.

How do I wait for an element to appear in Selenium Python?

You can use waits. Check for more information in Selenium waits. In the example below we are waiting 10 seconds for the element to be visible, using the function visibility_of_element_located. Save this answer.


1 Answers

 element = WebDriverWait(driver, 10).until(
            EC.invisibility_of_element_located((By.ID, 'button'))

you don't need to use while. it already waits for time that you present in WebDriverWait() function.

like image 60
Mahsum Akbas Avatar answered Oct 08 '22 20:10

Mahsum Akbas