- 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 is present in Selenium?
We can wait until an element is present in Selenium webdriver. This can be done with the help of synchronization concept. We have an explicit wait condition where we can pause or wait for an element before proceeding to the next step.
The explicit wait waits for a specific amount of time before throwing an exception. To verify if an element is present, we can use the expected condition presenceOfElementLocated.
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 ElementPresenceWait{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://www.tutorialspoint.com/about/about_careers.htm"; driver.get(url); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); // identify element and click() WebElement l=driver.findElement(By.linkText("Terms of Use")); l.click(); // explicit wait condition WebDriverWait w = new WebDriverWait(driver,3); // presenceOfElementLocated condition w.until(ExpectedConditions.presenceOfElementLocated (By.cssSelector("h1"))); // get text of element and print System.out.println("Element present having text:" + l.getText()); driver.quit() } }
Output
- Related Articles
- C# and Selenium: Wait Until Element is Present
- How to wait until an element no longer exists in Selenium?
- 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 verify an attribute is present in an element using Selenium WebDriver?
- Verifying whether an element present or visible in Selenium Webdriver
- Test if element is present using Selenium WebDriver?
- How to get Selenium to wait for ajax response?
- What is implicit wait in Selenium with python?
- How to wait for iFrames to load completely in Selenium webdriver?
- Wait for an Ajax call to complete with Selenium 2 WebDriver.
- How to verify if an element is displayed on screen in Selenium?
- How to use JavaScript in Selenium to click an Element?
- What is the explicit wait in Selenium with python?

Advertisements