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;
                        }
                    }
                );
            }
        }
    }