public function selectByPartialText($text) { $options = $this->_element->findElements(By::xPath(".//option[contains(text(), '" . $text . "')]")); $matched = false; foreach ($options as $option) { if (!$option->isSelected()) { $option->click(); } $matched = true; } if (!$matched) { throw new \Exception("Cannot locate option in select element with text: " . $text); } }
public function testSelectByPartialTextShouldSelect() { $select = new SelectElement($this->_driver->findElement(By::id("sel1"))); $select->selectByPartialText("Red"); $this->assertTrue($select->getElement()->findElement(By::xPath("option[@value = 2]"))->isSelected()); $select = new SelectElement($this->_driver->findElement(By::id("sel2"))); $select->selectByPartialText("peppers"); $this->assertTrue($select->getElement()->findElement(By::xPath("option[@value = 'greenpeppers']"))->isSelected()); }