

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- How do you make Selenium 2.0 wait for the page to load?
- How to add 10 seconds to a JavaScript date object?
- How to run a method every 10 seconds in Android?
- Getting Selenium to pause for X seconds.
- What is implicit wait in Selenium with python?
- C# and Selenium: Wait Until Element is Present
- Explain explicit wait in Selenium webdriver in Python.
- Explain implicit wait in Selenium webdriver in Python.
- 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
- How to run a method every 10 seconds in Android using Kotlin?
- What are the different types of wait available in Selenium?
- How to wait until an element is present in Selenium?
- Wait until page is loaded with Selenium WebDriver for Python.
Advertisements