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

io.magentys.cinnamon.webdriver.collections.ElementListCache Maven / Gradle / Ivy

There is a newer version: 0.2.0
Show newest version
package io.magentys.cinnamon.webdriver.collections;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.pagefactory.ElementLocator;

import java.util.List;

class ElementListCache {

    private final ElementLocator elementLocator;
    private List cachedElements;

    public ElementListCache(final ElementLocator locator, List elements) {
        this.elementLocator = locator;
        setElements(elements);
    }

    public synchronized List getElements() {
        if (cachedElements == null) {
            setElements(elementLocator.findElements());
        }
        invalidateCache();
        return cachedElements;
    }

    public synchronized void setElements(List cachedElements) {
        this.cachedElements = cachedElements;
    }

    private void invalidateCache() {
        List elements = elementLocator.findElements();
        if (elements.size() != cachedElements.size()) {
            setElements(elements);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy