Nagarjuna Reddy
Nagarjuna Reddy

Reputation: 819

Implicitwait not waiting for the specified duration in the code mentioned below

Selenium webdriver have to wait for 30 seconds and 5 seconds where it's mentioned in the code. But noticed that webdriver is skipping that. What's the reason and how can i make the webdriver wait.

System.out.println("Before 5"+date.toString());

driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

System.out.println("After 5"+date.toString());

Link to the complete code can be found here https://drive.google.com/file/d/0B4SgyzyvwKhiUk9KVldTa2ZGUkE/view?usp=sharing

Upvotes: 0

Views: 493

Answers (2)

Shi Linjie
Shi Linjie

Reputation: 1

You want to wait 5s.You can try:

  1. Thread.sleep(5000);
  2. (new WebDriverWait(driver, 5)) .until(new ExpectedCondition<WebElement>()

Upvotes: 0

Paras
Paras

Reputation: 3235

Implicit wait doesn't work like the normal Thread.sleep() where you put 5s time and your main thread gets halted and wait for 5 seconds.

It will work with the WebDriver Instance where it will wait for a particular element on a web page to appear for time mentioned in the wait. If there are no elements to identify i.e. element is already loaded in dom, your implicit wait won't wait for that period of time.

So when you say:-

System.out.println("Before 5"+date.toString());
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
System.out.println("After 5"+date.toString());

It won't show you the time difference of 5 seconds.

If there would have been any element which isn't loaded in dom it would have wait for 5 seconds.

System.out.println("Before 5"+date.toString());
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.id("some id")).sendKeys("Some Text")
System.out.println("After 5"+date.toString());  |
                                                |------- Here if the element isn't loaded in dom, then webdriver would wait for 5 seconds.

More information on Waits

Upvotes: 1

Related Questions