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

nl.hsac.fitnesse.fixture.util.selenium.SelectHelper Maven / Gradle / Ivy

There is a newer version: 5.3.17
Show newest version
package nl.hsac.fitnesse.fixture.util.selenium;

import nl.hsac.fitnesse.fixture.util.selenium.by.ConstantBy;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import java.util.List;

/**
 * Helper to determine which value(s) of a select is currently selected.
 */
public class SelectHelper {
    private static final By SELECTED_OPTIONS_BY = ConstantBy.getSelectedOptionsBy();
    private final WebElement selectElement;

    public SelectHelper(WebElement element) {
        selectElement = element;
    }

    public WebElement getFirstSelectedOption() {
        List selectedOptions = getAllSelectedOptions();
        return selectedOptions.isEmpty()? null : selectedOptions.get(0);
    }

    public List getAllSelectedOptions() {
        return selectElement.findElements(SELECTED_OPTIONS_BY);
    }

    /**
     * @param element element to check
     * @return true if element is indeed a 'select'.
     */
    public static boolean isSelect(WebElement element) {
        String tagName = element.getTagName();
        return "select".equalsIgnoreCase(tagName);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy