Exemplo n.º 1
0
 public function selectOption($select, $option)
 {
     $el = $this->findField($select);
     if ($el->getTagName() != 'select') {
         $els = $this->matchCheckables($select);
         $radio = null;
         foreach ($els as $el) {
             $radio = $this->findCheckable($el, $option, true);
             if ($radio) {
                 break;
             }
         }
         if (!$radio) {
             throw new ElementNotFound($select, "Radiobutton with value or name '{$option} in");
         }
         $radio->click();
         return;
     }
     $wdSelect = new \WebDriverSelect($el);
     if ($wdSelect->isMultiple()) {
         $wdSelect->deselectAll();
     }
     if (!is_array($option)) {
         $option = array($option);
     }
     $matched = false;
     foreach ($option as $opt) {
         try {
             $wdSelect->selectByVisibleText($opt);
             $matched = true;
         } catch (\NoSuchElementException $e) {
         }
     }
     if ($matched) {
         return;
     }
     foreach ($option as $opt) {
         try {
             $wdSelect->selectByValue($opt);
             $matched = true;
         } catch (\NoSuchElementException $e) {
         }
     }
     if ($matched) {
         return;
     }
     if ($matched) {
         return;
     }
     // partially matching
     foreach ($option as $opt) {
         try {
             $optElement = $el->findElement(\WebDriverBy::xpath('//option [contains (., "' . $opt . '")]'));
             $matched = true;
             if (!$optElement->isSelected()) {
                 $optElement->click();
             }
         } catch (\NoSuchElementException $e) {
         }
     }
     if ($matched) {
         return;
     }
     throw new ElementNotFound(json_encode($option), "Option inside {$select} matched by name or value");
 }