How to use wait in selenium java?

+3 votes
I am new to selenium and am trying to make the browser wait till the user input is fed to the text box. How can I do that? Can someone help me please?
Dec 18, 2018 in Selenium by Anjali
• 2,900 points
62 views

1 answer to this question.

+2 votes

There are different types of wait you can use :

Waits in selenium 

You can use implicit wait like this:

System.setProperty("webdriver.chrome.driver","Your\\path\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(TimeOut, TimeUnit.SECONDS);

You can also explicit wait like this :

System.setProperty("webdriver.chrome.driver","Your\\path\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
WebDriverWait wait = new WebDriverWait(WebDriverRefrence,TimeOut)

You can use the following methods to wait that is basically used to put you thread to sleep and also causes an Interrupted Exception so in order to handle the exception we use:

public static void main(String[] args) throws InterruptedException 
{
     System.setProperty("webdriver.chrome.driver","Your\\path\\chromedriver.exe");
     WebDriver driver = new ChromeDriver();
     driver.get("https://www.google.com");//Open google
     Thread.sleep(5000);// here time is in miliseconds so 5000 is 5 second and it will wait 5 seconds
     driver.close();//close the browser
}


Hope this helps.

answered Dec 18, 2018 by Nabarupa

Related Questions In Selenium

0 votes
1 answer

How to wait for the webpage to load in selenium using java

Firstly, when you launch a web application, ...READ MORE

answered Aug 28, 2018 in Selenium by bug_seeker
• 15,350 points
140 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,050 points
1,819 views
0 votes
1 answer

How to perform mouse hovering in Selenium WebDriver (Java)?

You many not actually be able to ...READ MORE

answered Apr 3, 2018 in Selenium by nsv999
• 5,050 points

edited Apr 4, 2018 by nsv999 2,630 views
0 votes
1 answer

How to use Actions class in Selenium Webdriver?

In seleniun webdriver it is not mandatory ...READ MORE

answered Apr 4, 2018 in Selenium by Damon Salvatore
• 5,510 points
2,395 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,050 points
423 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
777 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
416 views
0 votes
1 answer
0 votes
1 answer

How to use Implicit wait in selenium?

There are various types of wait in ...READ MORE

answered Dec 24, 2018 in Selenium by Nabarupa
46 views