lib/WebDriverExpectedCondition.php
public static function elementSelectionStateToBe($element_or_by, $selected)
    {
        if ($element_or_by instanceof WebDriverElement) {
            return new static(
                function () use ($element_or_by, $selected) {
                    return $element_or_by->isSelected() === $selected;
                }
            );
        } else {
            if ($element_or_by instanceof WebDriverBy) {
                return new static(
                    function (WebDriver $driver) use ($element_or_by, $selected) {
                        try {
                            $element = $driver->findElement($element_or_by);

                            return $element->isSelected() === $selected;
                        } catch (StaleElementReferenceException $e) {
                            return null;
                        }
                    }
                );
            }
        }
    }
public static function elementSelectionStateToBe($element_or_by, $selected)
    {
        if ($element_or_by instanceof WebDriverElement) {
            return new static(
                function () use ($element_or_by, $selected) {
                    return $element_or_by->isSelected() === $selected;
                }
            );
        } else {
            if ($element_or_by instanceof WebDriverBy) {
                return new static(
                    function (WebDriver $driver) use ($element_or_by, $selected) {
                        try {
                            $element = $driver->findElement($element_or_by);

                            return $element->isSelected() === $selected;
                        } catch (StaleElementReferenceException $e) {
                            return null;
                        }
                    }
                );
            }
        }
    }
public static function elementSelectionStateToBe ( $ element_or_by , $ selected ) { if ( $ element_or_by instanceof WebDriverElement ) { return new static ( function ( ) use ( $ element_or_by , $ selected ) { return $ element_or_by -> isSelected ( ) === $ selected ; } ) ; } else { if ( $ element_or_by instanceof WebDriverBy ) { return new static ( function ( WebDriver $ driver ) use ( $ element_or_by , $ selected ) { try { $ element = $ driver -> findElement ( $ element_or_by ) ; return $ element -> isSelected ( ) === $ selected ; } catch ( StaleElementReferenceException $ e ) { return null ; } } ) ; } } }
An expectation for checking if the given element is selected.

@param mixed $element_or_by Either the element or the locator.
@param bool $selected The required state.
@return static Condition returns whether the element is selected.
An expectation for checking if the given element is selected .