public function execute() { $this->testCase->byText('{{Add Tracking Number}}')->click(); $this->testCase->sleep('1s'); // Give the UI time to update $count = 0; do { $count++; } while ($this->webDriver->elementExists($this->theme->getShippingCarrierXpath($count), WebDriver::BY_XPATH)); $count--; // $count was the last one that DOESN'T exist. Go back one. if ($this->carrier) { $select = new WebDriverSelect($this->webDriver->byXpath($this->theme->getShippingCarrierXpath($count))); if (strpos($this->carrier, 'label=') === 0) { $carrier = substr($this->carrier, strlen('label=')); $select->selectByVisibleText($carrier); } else { $select->selectByValue($this->carrier); } } if ($this->title) { $element = $this->webDriver->byXpath($this->theme->getShippingTitleXpath($count)); $element->clear(); $element->sendKeys($this->title); } if ($this->number) { $element = $this->webDriver->byXpath($this->theme->getShippingTrackingNumberXpath($count)); $element->clear(); $element->sendKeys($this->number); } }
protected function setSelect(WebDriverElement $element, $value) { $select = new WebDriverSelect($element); if ($select->isMultiple()) { $select->deselectAll(); } if (!is_array($value)) { $value = [$value]; } foreach ($value as $v) { if (strpos($v, 'value:') === 0) { $select->selectByValue(substr($value, 6)); } else { $select->selectByVisibleText($v); } } }
public function testCategoryTreeExtractorWithNewProductCategories() { $this->getAction(Login::ACTION)->execute(); $this->getNavigator(AdminMenu::NAVIGATOR)->navigateTo('Catalog/Manage Products'); $this->byText('Add Product')->click(); $extractor = $this->getExtractor(Attribute::EXTRACTOR); /* @var $extractor Attribute */ $attributeSet = new WebDriverSelect($extractor->getElementByLabel('Attribute Set')); $attributeSet->selectByVisibleText('Default'); $attributeSet = new WebDriverSelect($extractor->getElementByLabel('Product Type')); $attributeSet->selectByVisibleText('Simple Product'); $this->byText('Continue')->click(); // Add it to a category $this->getNavigator(Tab::NAVIGATOR)->navigateTo('Categories::Product Categories'); $extractor = $this->getExtractor(CategoryTreeNode::EXTRACTOR); /* @var $extractor CategoryTreeNode */ $element = $extractor->getNode('Men/Shirts'); $this->assertWebDriverElement($element); }
/** * Append the given text to the given element. * Can also add a selection to a select box. * * ``` php * <?php * $I->appendField('#mySelectbox', 'SelectValue'); * $I->appendField('#myTextField', 'appended'); * ?> * ``` * * @param string $field * @param string $value * @throws \Codeception\Exception\ElementNotFound */ public function appendField($field, $value) { $el = $this->findField($field); switch ($el->getTagName()) { //Multiple select case "select": $matched = false; $wdSelect = new WebDriverSelect($el); try { $wdSelect->selectByVisibleText($value); $matched = true; } catch (NoSuchElementException $e) { } try { $wdSelect->selectByValue($value); $matched = true; } catch (NoSuchElementException $e) { } if ($matched) { return; } throw new ElementNotFound(json_encode($value), "Option inside {$field} matched by name or value"); break; case "textarea": $el->sendKeys($value); return; break; case "div": //allows for content editable divs $el->sendKeys(WebDriverKeys::END); $el->sendKeys($value); return; break; //Text, Checkbox, Radio //Text, Checkbox, Radio case "input": $type = $el->getAttribute('type'); if ($type == 'checkbox') { //Find by value or css,id,xpath $field = $this->findCheckable($this->webDriver, $value, true); if (!$field) { throw new ElementNotFound($value, "Checkbox or Radio by Label or CSS or XPath"); } if ($field->isSelected()) { return; } $field->click(); return; } elseif ($type == 'radio') { $this->selectOption($field, $value); return; } else { $el->sendKeys($value); return; } break; default: } throw new ElementNotFound($field, "Field by name, label, CSS or XPath"); }
public function execute($save = true) { $this->save = $save; try { $this->clickActionButton->click($this->translator->translate('Add New Condition')); } catch (NoSuchElementException $e) { // Don't worry about it. Perhaps we're not on the main terms page. } $element = $this->attribute->getElementByLabel($this->translator->translate('Condition Name')); $this->setValue($element, $this->name); if ($this->contentAs) { $select = new WebDriverSelect($this->attribute->getElementByLabel($this->translator->translate('Show Content as'))); $select->selectByVisibleText($this->contentAs); } if ($this->status) { $select = new WebDriverSelect($this->attribute->getElementByLabel($this->translator->translate('Status'))); $select->selectByVisibleText($this->status); } if ($this->storeView) { $storeViewElement = $this->attribute->getElementByLabel($this->translator->translate('Store View')); $xpath = sprintf('//option[.="%s"]', $this->storeView); $element = $storeViewElement->findElement(WebDriverBy::xpath($xpath)); $element->click(); } $element = $this->attribute->getElementByLabel($this->translator->translate('Checkbox Text')); $this->setValue($element, $this->checkboxText); $element = $this->attribute->getElementByLabel($this->translator->translate('Content')); $this->setValue($element, $this->content); $element = $this->attribute->getElementByLabel($this->translator->translate('Content Height (css)')); $this->setValue($element, $this->contentHeight); $this->preSave(); if ($this->save) { $this->webDriver->executeScript('window.scrollTo(0, 0);'); $this->clickActionButton->click($this->translator->translate('Save Condition')); } }
/** * @param WebDriverSelect $select * @param string|string[] $value * @throws \Exception */ protected function _setFieldSelect(WebDriverSelect $select, $value) { $valueList = (array) $value; if ($select->isMultiple()) { $select->deselectAll(); } $matched = false; foreach ($valueList as $value) { try { $select->selectByVisibleText($value); $matched = true; } catch (NoSuchElementException $e) { } } if ($matched) { return; } foreach ($valueList as $value) { try { $select->selectByValue($value); $matched = true; } catch (NoSuchElementException $e) { } } if (false === $matched) { throw new \Exception("Cannot select option `{$value}`"); } }