src/Component/Select2.php
public function getFirstSelectedOption(): WebDriverElement
    {
        if (!$this->isMultiple()) {
            return $this->findByCss($this->select2Selector . ' ' . self::SIMPLESELECT_SELECTED_OPTION_SELECTOR);
        }

        $selected = $this->findMultipleByCss(
            $this->select2Selector . ' ' . self::MULTISELECT_SELECTED_OPTIONS_SELECTOR
        );

        if (count($selected) === 0) {
            throw new NoSuchElementException('No options are selected');
        }

        return reset($selected);
    }
public function getFirstSelectedOption(): WebDriverElement
    {
        if (!$this->isMultiple()) {
            return $this->findByCss($this->select2Selector . ' ' . self::SIMPLESELECT_SELECTED_OPTION_SELECTOR);
        }

        $selected = $this->findMultipleByCss(
            $this->select2Selector . ' ' . self::MULTISELECT_SELECTED_OPTIONS_SELECTOR
        );

        if (count($selected) === 0) {
            throw new NoSuchElementException('No options are selected');
        }

        return reset($selected);
    }
@throws NoSuchElementException

@return WebDriverElement The first selected option in multi-select (or the currently selected option
in a normal select)