Exemple #1
0
 public function testClearSelectedOptions()
 {
     $this->writePage();
     $this->webdriver->byXpath('//*[@id="select"]/option[1]')->click();
     $fast = new FastSelectElement($this->webdriver, '//select[@id="select"]');
     $fast->clearSelectedOptions();
     $result = $fast->getSelectedOptions();
     self::assertCount(0, $result);
 }
 protected function handleElementSetting($elementId, $value)
 {
     $element = $this->webDriver->byId($elementId);
     if (strtolower($element->getTagName()) === 'select') {
         if (!is_array($value)) {
             $value = [$value];
         }
         $xpath = sprintf('//select[@id="%s"]', $elementId);
         $select = new FastSelectElement($this->webDriver, $xpath);
         //            $options = $select->getAllSelectedOptions();
         $select->clearSelectedOptions();
         foreach ($value as $v) {
             $xpath = sprintf('//select[@id="%s"]', $elementId);
             $matches = null;
             if (preg_match('/^label=(.+)$/', $v, $matches)) {
                 $xpath .= sprintf('/descendant::option[.="%s"]', str_replace('"', '\\"', $matches[1]));
                 $this->webDriver->byXpath($xpath)->click();
             } else {
                 $xpath .= sprintf('/descendant::option[@value="%s"]', str_replace('"', '\\"', $v));
                 $this->webDriver->byXpath($xpath)->click();
             }
         }
     } else {
         if (strtolower($element->getTagName()) === 'input') {
             if ($element->getAttribute('value') != $value) {
                 $element->clear();
                 $element->sendKeys($value);
                 $this->dataChanged = true;
             }
         }
     }
 }