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, 2019 in Selenium by Inder
103 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, 2019 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 Aug 14, 2019 in Selenium by Abha
• 27,920 points
138 views
0 votes
1 answer

How can I create a POM test case in Selenium Webdriver?

Hey Akshay, follow these steps to create ...READ MORE

answered May 12, 2019 in Selenium by Anvi
• 14,030 points
251 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,710 points
1,426 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,460 points
432 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,510 points
166 views
0 votes
1 answer
0 votes
2 answers

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

You first need to download chrome driver ...READ MORE

answered Aug 26, 2019 in Selenium by Abha
• 27,920 points
553 views
0 votes
1 answer