Can anyone suggest how can I use Explicit wait in my automation test cases using Webdriver?

0 votes
Can anyone suggest how can I use Explicit wait in my automation test cases using Webdriver?
Jul 22 in Selenium by Inder
32 views

1 answer to this question.

0 votes

Hi Inder, you can use Explicit wait in any automation test script in the following manner:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class ExplicitWaitDemo {
public static void main(String[] args) {

WebDriver driver = new ChromeDriver();
driver.get("http://www.edureka.co/");

driver.findElement(By.xpath("//button[text()='Sign Up']")).click();

// Create object of WebDriverWait class and it will wait max of 20 seconds.

WebDriverWait wait = new WebDriverWait(driver, 20);

// Here we will wait until element is not visible, if element is visible then it will return web element or else it will throw exception

WebElement element = wait
.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//p[text()='WebDriver']")));

boolean status = element.isDisplayed();

if (status) {

System.out.println("===== WebDriver is visible======");

} else {

System.out.println("===== WebDriver is not visible======");

}
}
}
answered Jul 22 by Abha

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

Can anyone suggest how can I restore cookies in new browser window using Webdriver?

Hey Akshay, following code snippet would help ...READ MORE

answered 3 days ago in Selenium by Abha
• 19,130 points
14 views
0 votes
1 answer

Can anyone help me that how to run Selenium WebDriver test cases in Chrome?

Download the executable driver from: ChromeDriver Download Before ...READ MORE

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

Impilicit wait vs Explicit wait vs Fluent wait

Implicit wait: Your telling the WebDriver the ...READ MORE

answered Apr 13, 2018 in Selenium by king_kenny
• 3,610 points
695 views
0 votes
1 answer

Implicit wait & Explicit wait in selenium WebDriver

Implicit Wait:  While loading a web page in ...READ MORE

answered May 24, 2018 in Selenium by Meci Matt
• 9,400 points
145 views
0 votes
1 answer

Not able to use “explicit wait” in my code

To wait until the entire data has ...READ MORE

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