- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to wait until an element no longer exists in Selenium?
We can wait until an element no longer exists in Selenium webdriver. This can be achieved with synchronization in Selenium. We shall add an explicit wait criteria where we shall stop or wait till the element no longer exists.
Timeout exception is thrown once the explicit wait time has elapsed and the expected behavior of the element is still not available on the page. 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.
Example
Code Implementation.
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; public class ElementInvisibleWait{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://www.tutorialspoint.com/index.htm"); driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS); // identify element and click() driver.findElement(By.xpath("//*[text()='Library']")).click(); // explicit wait of invisibility condition WebDriverWait w = new WebDriverWait(driver,5); // invisibilityOfElementLocated condition w.until(ExpectedConditions. invisibilityOfElementLocated(By.xpath("//*[@class='mui-btn']"))); // get page title of next page System.out.println("Page title after click:" + driver.getTitle()); driver.close() } }
Output
- Related Articles
- How to wait until an element is present in Selenium?
- C# and Selenium: Wait Until Element is Present
- Need Selenium to wait until the document is ready
- Need to wait until page is completely loaded - Selenium WebDriver
- Wait until page is loaded with Selenium WebDriver for Python.
- How to check if Element exists in c# Selenium drivers?
- Checking if element exists with Python Selenium.
- How to verify specific text exists within an attribute in Selenium IDE?
- How to get Selenium to wait for ajax response?
- How to wait for iFrames to load completely in Selenium webdriver?
- Wait for an Ajax call to complete with Selenium 2 WebDriver.
- How to use JavaScript in Selenium to click an Element?
- Selenium with C Sharp - How to perform Explicit Wait method?
- Make Selenium wait 10 seconds.
- How to wait for options in a select to be populated in Selenium?

Advertisements