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

org.fluentlenium.core.proxy.ElementListSupplierLocator Maven / Gradle / Ivy

package org.fluentlenium.core.proxy;

import org.fluentlenium.utils.SupplierOfInstance;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.pagefactory.ElementLocator;

import java.util.List;
import java.util.function.Supplier;

/**
 * Element locator implemented by a {@link Supplier} of list of {@link WebElement}.
 */
public class ElementListSupplierLocator implements ElementLocator {
    private final Supplier> elementsSupplier;

    /**
     * Creates a new element list supplier locator
     *
     * @param elements element list instance
     */
    public ElementListSupplierLocator(List elements) {
        elementsSupplier = new SupplierOfInstance<>(elements);
    }

    /**
     * Creates a new element list supplier locator
     *
     * @param elementsSupplier element list supplier
     */
    public ElementListSupplierLocator(Supplier> elementsSupplier) {
        this.elementsSupplier = elementsSupplier;
    }

    @Override
    public WebElement findElement() {
        List webElements = elementsSupplier.get();
        if (webElements != null && !webElements.isEmpty()) {
            return webElements.iterator().next();
        }
        return null;
    }

    @Override
    public List findElements() {
        return elementsSupplier.get();
    }

    @Override
    public String toString() {
        return String.valueOf(elementsSupplier);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy