Video Tutorial link https://youtu.be/0Iw7OdbNZcU
package practice;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
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.FluentWait;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
import com.google.common.base.Function;
public class WaitExample {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\mprem\\OneDrive\\Desktop\\SelJars\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
WebDriverWait wt=new WebDriverWait(driver, 25);
//driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.get("https://www.magneticautomation.in/2020/05/implicit-explicit-wait-example.html");
driver.findElement(By.xpath("//*[@id=\"post-body-6247563354204017858\"]/button")).click();
//WebElement E=driver.findElement(By.xpath("//p[text()='QTP']"));
WebElement E=wt.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//p[text()='QTP']")));
System.out.println(E.isDisplayed());
//ExpectedConditions.
Wait wait = new FluentWait(driver)
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofSeconds(3))
.ignoring(NoSuchElementException.class);
WebElement rft = wait.until(new Function() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.xpath("//p[text()='RFT123']"));
}
});
System.out.println("RFt text displaying status is "+rft.isDisplayed());
}
}
Comments
Post a Comment