mercredi 22 mars 2017

Selenium FluentWait and element not visible exception

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");

Aucun commentaire:

Enregistrer un commentaire