query('xpath:.//li[not(@optgroup)]')->all(); } /** * Get text of selected element. * * @return string */ public function getText() { return $this->query('xpath:./button')->one()->getText(); } /** * Select option by text. * * @param string $text option text to be selected * * @return $this */ public function select($text) { if ($text === $this->getText()) { return $this; } $option = null; if ($this->query("xpath:.//li[not(@optgroup)]/*")->count() > 0) { foreach ($this->getOptions() as $element) { if ($text === $element->getText()) { $option = $element; break; } } } else { $option = $this->query('xpath:.//li[not(@optgroup) and text()='.CXPathHelper::escapeQuotes($text).']')->one(); } if ($option !== null) { for ($i = 0; $i < 5; $i++) { try { $this->waitUntilClickable()->click(); $option->scrollIntoView(); $option->click(); return $this; } catch (Exception $exception) { // Code is not missing here. } } } throw new Exception('Failed to select dropdown option "'.$text.'".'); } /** * Alias for select. * @see self::select * * @param string $text option text to be selected * * @return $this */ public function fill($text) { return $this->select($text); } /** * Alias for getText. * @see self::getText * * @return string */ public function getValue() { return $this->getText(); } }