/** * @Then /^I fill "((?:[^"]|"")*)" with "((?:[^"]|"")*)"$/ */ public function iFillWith($field, $value) { $field = $this->unescape($field); $value = $this->unescape($value); $selector = $this->parseSelector($field); if (is_string($selector)) { $selector = By::xpath(strtr(self::LABEL_TO_INPUT_XPATH, array('{text}' => Xpath::quote($field)))); } $field = $this->tryRepeating(function () use($selector) { return $this->getElement($selector); }); if ($field->getTagName() == 'select') { $field->element(By::xpath('.//option[contains(., ' . Xpath::quote($value) . ')]'))->click(); return; } $type = $field->getAttribute('type'); if ($type === 'checkbox') { $value = $value === '1' || $value === 'on' || $value === 'true'; $selected = $field->isSelected(); if ($value !== $selected) { $field->click(); } return; } if ($type === 'radio') { $value = $value === '1' || $value === 'on' || $value === 'true'; $selected = $field->isSelected(); if ($selected && !$value) { throw new \RuntimeException(sprintf('Cannot uncheck a radio (a user in a web browser can\'t neither')); } $field->click(); return; } // text or textarea $field->clear(); $field->type($value); }
protected function getContextualActions($textFilter = null) { return $this->getElements(By::xpath('//div[contains(@class, "sub-actions")]//a[contains(.,"' . $textFilter . '")]')); }
/** * Converts a text selector to a By object. * * Tries to find magic expressions (css=#foo, xpath=//div[@id="foo"], id=foo, name=q, class=active). * * @return By|string returns a By instance when magic matched, the string otherwise */ protected function parseSelector($text) { if (0 === strpos($text, 'id=')) { return By::id(substr($text, 3)); } if (0 === strpos($text, 'xpath=')) { return By::xpath(substr($text, 6)); } if (0 === strpos($text, 'css=')) { return By::css(substr($text, 4)); } if (0 === strpos($text, 'name=')) { return By::name(substr($text, 5)); } if (0 === strpos($text, 'class=')) { return By::className(substr($text, 6)); } return $text; }