I'm trying to use FluentWait instead of sleep and this is my first practice. First of all and most importantly am I doing it right at all? Secondly I got through two elements so I thought it kind of works (PaymentMethod button and CheckOut button). Before I implemented FluentWait it wouldn't find them. And finally it won't find the third(backToDesktop button) element. Keeps throwing Element not visible, although I added the wait.ignore(ElementNotVisibleExcecption.class).
FluentWait<WebDriver> wait = new FluentWait<WebDriver>(login.getDriver());
wait.withTimeout(5, TimeUnit.SECONDS);
wait.pollingEvery(250, TimeUnit.MILLISECONDS);
wait.ignoring(NoSuchElementException.class);
wait.ignoring(ElementNotVisibleException.class);
WebElement paymentMethod = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return login.getDriver().findElement(By.xpath("//*[@id='paymentMethodHolder']/div[1]/div[1]/button"));
}
});
paymentMethod.click();
System.out.println("FOUND PAYMENTMETHOD BUTTON");
WebElement checkOut = wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return login.getDriver().findElement(By.xpath("//*[@id='checout-footer-buttons']/button[2]"));
}
});
checkOut .click();
System.out.println("FOUND KINNITA BUTTON");
WebElement backToDesktop= wait.until(new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return login.getDriver().findElement(By.className("modal-button-text"));
}
});
backToDesktop.click();
System.out.println("FOUND BACKTODESKTOP BUTTON");