src/Context/Form/FormContext.php
public function setValueForHierarchicalSelect($selector, TableNode $values)
    {
        $element = $this->getWorkingElement();
        // Try to selects by wrapper ID.
        $wrapper = $element->findById($selector);

        if (null !== $wrapper) {
            $labels = $wrapper->findAll('xpath', '//label[@for]');
        } else {
            $labels = $this->findLabels($selector);
        }

        if (empty($labels)) {
            throw new \Exception('No one hierarchical select was found.');
        }

        /** @var NodeElement $label */
        $label = reset($labels);
        $parent = $label->getParent();

        foreach (array_keys($values->getRowsHash()) as $i => $value) {
            /** @var NodeElement[] $selects */
            $selects = [];

            /** @var NodeElement $select */
            foreach ($parent->findAll('css', 'select') as $select) {
                if ($select->isVisible()) {
                    $selects[] = $select;
                }
            }

            if (!isset($selects[$i])) {
                throw new \InvalidArgumentException(sprintf(
                    'The value "%s" was specified for select "%s" but it does not exist.',
                    $value,
                    $i
                ));
            }

            $selects[$i]->selectOption($value);
            $this->waitAjaxAndAnimations();
        }
    }
public function setValueForHierarchicalSelect($selector, TableNode $values)
    {
        $element = $this->getWorkingElement();
        // Try to selects by wrapper ID.
        $wrapper = $element->findById($selector);

        if (null !== $wrapper) {
            $labels = $wrapper->findAll('xpath', '//label[@for]');
        } else {
            $labels = $this->findLabels($selector);
        }

        if (empty($labels)) {
            throw new \Exception('No one hierarchical select was found.');
        }

        /** @var NodeElement $label */
        $label = reset($labels);
        $parent = $label->getParent();

        foreach (array_keys($values->getRowsHash()) as $i => $value) {
            /** @var NodeElement[] $selects */
            $selects = [];

            /** @var NodeElement $select */
            foreach ($parent->findAll('css', 'select') as $select) {
                if ($select->isVisible()) {
                    $selects[] = $select;
                }
            }

            if (!isset($selects[$i])) {
                throw new \InvalidArgumentException(sprintf(
                    'The value "%s" was specified for select "%s" but it does not exist.',
                    $value,
                    $i
                ));
            }

            $selects[$i]->selectOption($value);
            $this->waitAjaxAndAnimations();
        }
    }
@param string $selector
@param TableNode $values

@throws ElementNotFoundException
@throws \Exception
@throws NoSuchElement

@Given /^(?:|I )select the following in "([^"]*)" hierarchical select:$/