- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Make Selenium wait 10 seconds.
We can make Selenium wait for 10 seconds. This can be done by using the Thread.sleep method. Here, the wait time (10 seconds) is passed as a parameter to the method.
We can also use the synchronization concept in Selenium for waiting. There are two kinds of wait − implicit and explicit. Both these are of dynamic nature, however the implicit wait is applied to every step of automation, the explicit wait is applicable only to a particular element.
Example
Code Implementation with sleep method.
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class WaitThrd{ public static void main(String[] args) throws InterruptedException{ System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://www.tutorialspoint.com/index.htm"); // wait time added Thread.sleep(200); // identify element, WebElement m=driver.findElement(By.id("gsc−i−id1")); m.sendKeys("Java"); driver.close(); } }
Example
Code Implementation with implicit wait.
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class WaitImplicit{ public static void main(String[] args) throws InterruptedException{ System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); // implicit wait driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS); driver.get("https://www.tutorialspoint.com/index.htm"); // identify element, WebElement m=driver.findElement(By.id("gsc−i−id1")); m.sendKeys("Python"); driver.close(); } }
Example
Code Implementation with explicit wait.
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 WaitExplicit{ public static void main(String[] args) throws InterruptedException{ System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("https://www.tutorialspoint.com/index.htm"); // identify element, WebElement l=driver.findElement(By.xpath("//*[text()='Library']")); l.click(); //explicit wait WebDriverWait w = new WebDriverWait(driver,7); //expected condition w.until(ExpectedConditions. invisibilityOfElementLocated(By.xpath("//*[@class='mui−btn']"))); driver.close(); } }
- Related Articles
- How do you make Selenium 2.0 wait for the page to load?
- What is implicit wait in Selenium with python?
- C# and Selenium: Wait Until Element is Present
- What is the explicit wait in Selenium with python?
- How to get Selenium to wait for ajax response?
- Need Selenium to wait until the document is ready
- Getting Selenium to pause for X seconds.
- How to wait until an element is present in Selenium?
- Wait until page is loaded with Selenium WebDriver for Python.
- What are the different types of wait available in Selenium?
- Best practice to wait for a change with Selenium Webdriver?
- Wait for complex page with JavaScript to load using Selenium.
- Need to wait until page is completely loaded - Selenium WebDriver
- Selenium with C Sharp - How to perform Explicit Wait method?
- How to wait until an element no longer exists in Selenium?

Advertisements