All Downloads are FREE. Search and download functionalities are using the official Maven repository.

uk.sponte.automation.seleniumpom.webdriverConditions.ElementPresentCondition Maven / Gradle / Ivy

There is a newer version: 3.0.14
Show newest version
package uk.sponte.automation.seleniumpom.webdriverConditions;

import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;

import javax.annotation.Nullable;

/**
 * WebDriver element condition for checking element's presence
 * Created by n450777 on 04/03/2016.
 */
public class ElementPresentCondition implements ExpectedCondition {
    private WebElement element;

    public ElementPresentCondition(WebElement element) {
        this.element = element;
    }

    @Nullable
    @Override
    public WebElement apply(@Nullable WebDriver webDriver) {
        try {
            element.getTagName();
            return element;
        } catch (NoSuchElementException ex) {
            return null;
        } catch(StaleElementReferenceException ex) {
            return null;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy