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

org.bithill.selenium.condition.SelectConditions Maven / Gradle / Ivy

There is a newer version: 1.0
Show newest version
package org.bithill.selenium.condition;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.Select;

/** Collection of {@link ExpectedCondition}s for {@link Select}. */
public class SelectConditions
{
    /**
     * Condition met when a <select> has at least given count of <option>s.
     *
     * @param locator locator of the select
     * @param minValuesCount minimal number of options required
     * @return the matching select
     */
    public static ExpectedCondition()
        {
            private int currentValueCount = 0;

            @Override
            public Select apply(WebDriver driver)
            {
                WebElement element = driver.findElement(locator);
                if (element.isDisplayed())
                {
                    Select select = new Select(element);
                    currentValueCount = select.getOptions().size();
                    if (currentValueCount >= minValuesCount) { return select; }
                }
                return null;
            }

            public String toString()
            {
                return String.format("Value count should be >= %d. Current count: %d",
                                     minValuesCount, currentValueCount);
            }
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy