本文整理汇总了PHP中Behat\Mink\Element\NodeElement类的典型用法代码示例。如果您正苦于以下问题:PHP NodeElement类的具体用法?PHP NodeElement怎么用?PHP NodeElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NodeElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fillForm
/**
* Fuzz fill all form fields with random data
*
* @param Element\NodeElement $form
*/
protected function fillForm(Element\NodeElement $form)
{
$inputs = $form->findAll('css', 'input[type="text"]');
foreach ($inputs as $i) {
/** @var Element\NodeElement $i */
if ($i->isVisible()) {
if ($i->hasAttribute('name')) {
$name = $i->getAttribute('name');
$value = $this->getFakerValue($name);
} else {
$value = $this->faker()->text();
}
$i->setValue($value);
}
}
$passwords = $form->findAll('css', 'input[type="password"]');
$password = $this->faker()->password;
foreach ($passwords as $p) {
if ($p->isVisible()) {
$p->setValue($password);
}
}
$selects = $form->findAll('css', 'select');
foreach ($selects as $s) {
/** @var Element\NodeElement $s */
if ($s->isVisible()) {
$s->selectOption($s->find('css', 'option')->getAttribute('name'));
}
}
$checkboxes = $form->findAll('css', 'checkbox');
foreach ($checkboxes as $c) {
/** @var Element\NodeElement $c */
if ($c->isVisible()) {
$c->check();
}
}
$radios = $form->findAll('css', 'input[type="radio"]');
$radio_names = array();
foreach ($radios as $r) {
/** @var Element\NodeElement $r */
if ($r->isVisible()) {
if ($r->hasAttribute('name')) {
$name = $r->getAttribute('name');
if (!isset($radio_names[$name])) {
$radio_names[$name] = true;
$r->click();
}
}
}
}
}
示例2: __construct
public function __construct(NodeElement $node, Session $session)
{
if (!$node->hasClass(self::NOTICE_CLASS)) {
throw new \InvalidArgumentException(sprintf('Provided node does not have class %s', self::NOTICE_CLASS));
}
parent::__construct($node->getXpath(), $session);
}
示例3: getNameProperty
/**
* Returns the name
* @param NodeElement $slide
* @return string
*/
public function getNameProperty(NodeElement $slide)
{
$selectors = Helper::getRequiredSelectors($this, ['slideImage', 'slideLink', 'slideName']);
$nameElement = $slide->find('css', $selectors['slideName']);
$names = ['imageAlt' => $slide->find('css', $selectors['slideImage'])->getAttribute('alt'), 'linkTitle' => $slide->find('css', $selectors['slideLink'])->getAttribute('title'), 'name' => $nameElement->getText(), 'nameTitle' => $nameElement->getAttribute('title')];
return Helper::getUnique($names);
}
示例4: createFromNode
public static function createFromNode(NodeElement $node)
{
$message = $node->find('css', '.noty_text')->getHtml();
//$x = $node->getOuterHtml();
$class = $node->getAttribute('class');
switch ($class) {
case 'noty_alert':
$type = 'alert';
break;
case 'noty_warning':
$type = 'warning';
break;
case 'noty_error':
$type = 'error';
break;
case 'noty_information':
$type = 'information';
break;
case 'noty_success':
$type = 'success';
break;
default:
$type = 'default';
}
return new NotyMessage($node, $type, $message);
}
示例5: getEvaluation
/**
* Helper function how to read the evaluation from the evaluation element
* @param NodeElement $element
* @return string
*/
protected function getEvaluation($element)
{
$evaluation = $element->getAttribute('content');
$evaluation = floatval($evaluation);
$evaluation *= 2;
return (string) $evaluation;
}
示例6: fromNodeElement
/**
* Creates Element instance based on existing NodeElement instance.
*
* @param NodeElement $node_element Node element.
* @param IPageFactory $page_factory Page factory.
*
* @return static
* @throws ElementException When page factory is missing.
*/
public static function fromNodeElement(NodeElement $node_element, IPageFactory $page_factory = null)
{
if (!isset($page_factory)) {
throw new ElementException('Page factory is required to create this element', ElementException::TYPE_PAGE_FACTORY_REQUIRED);
}
$selenium_selector = array(How::XPATH => $node_element->getXpath());
return new static($selenium_selector, $page_factory);
}
示例7: parse
public function parse(NodeElement $node)
{
$this->node = $node;
$elems = $node->findAll('css', 'li');
foreach ($elems as $elem) {
$notyMessage = NotyMessage::createFromNode($elem);
$this->messages[] = $notyMessage;
}
}
示例8: reverse
public static function reverse(NodeElement $buttonNode, Button $buttonObj, Elements $elements = null)
{
if ($buttonNode->getTagName() === 'button') {
$buttonObj->setNode($buttonNode);
} else {
throw new \LogicException('tag mismatch');
}
$parents = $buttonObj->getParents();
$outer = $buttonNode->getOuterHtml();
$label = $buttonNode->getText();
if ($label) {
$buttonObj->setLabel($label);
} else {
$x = 1;
}
//return;
/* $elem = [];
$id = $button->getAttribute('id');
$html = $button->getOuterHtml();
$test = '/<[a-z]+\s([^>]*)/';
if (preg_match($test, $html, $matches)) {
preg_match_all('/([a-z]+=".*?")/', $matches[1], $attribs1);
$attribs = preg_split('/ /', $matches[1], null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
$elem['attr'] = $attribs;
}
if ($button->getTagName() === 'a') {
$href = $button->getAttribute('href');
$elem['href'] = $href;
}
if (!$id) {
$dt = $content->find('css', 'table.table-columnfilter');
if ($dt) {
//skip datatable;
//continue;
}
$label = $button->getText();
$xpath = $button->getXpath();
$elem['xpath'] = $xpath;
$elem['label'] = $label;
} else {
$label = $button->getText();
$elements['buttons'][] = ['id' => $id, 'label' => $label];
}
$elements['buttons'][] = $elem;*/
}
示例9: getOrderPositionData
/**
* Helper function returns the data of an order position
* @param NodeElement $position
* @param string[] $selectors
* @return array
*/
private function getOrderPositionData(NodeElement $position, array $selectors)
{
$data = [];
foreach ($selectors as $key => $selector) {
$element = $position->find('css', $selector);
$data[$key] = $element->getText();
if ($key !== 'product') {
$data[$key] = Helper::floatValue($data[$key]);
}
}
return $data;
}
示例10: getScopeData
/**
* @param NodeElement $scopeBlock
*
* @return array
*/
protected function getScopeData(NodeElement $scopeBlock)
{
$ratio = $scopeBlock ? $scopeBlock->find('css', '.literal-progress')->getHtml() : '';
$state = $scopeBlock ? explode('-', $scopeBlock->find('css', '.progress')->getAttribute('class'))[1] : '';
$missingValuesBlocks = $scopeBlock ? $scopeBlock->findAll('css', '.missing-attributes [data-attribute]') : [];
$missingValues = [];
if (!empty($missingValuesBlocks)) {
foreach ($missingValuesBlocks as $missingValuesBlock) {
$attributeCode = $missingValuesBlock->getAttribute('data-attribute');
$attributeLabel = $missingValuesBlock->getHtml();
$missingValues[$attributeCode] = $attributeLabel;
}
}
return ['ratio' => $ratio, 'state' => $state, 'missing_values' => $missingValues];
}
示例11: findAll
/**
* @return NodeElement[]
*/
public function findAll()
{
if (null === $this->parent) {
throw new \RuntimeException(sprintf('An object "%s" instantiated incorrectly.', __CLASS__));
}
return $this->parent->findAll('xpath', (string) $this);
}
示例12: findCommentMessage
/**
* @param NodeElement $element
*
* @return NodeElement|mixed|null
*/
protected function findCommentMessage(NodeElement $element)
{
return $element->find('css', 'span.message');
}
示例13: waitForModalToAppear
/**
* @param NodeElement $modalContainer
* @param string $appearClass
*
* @todo it really shouldn't be here :)
*/
protected function waitForModalToAppear(NodeElement $modalContainer, $appearClass = 'in')
{
$this->getDocument()->waitFor(1, function () use($modalContainer, $appearClass) {
return false !== strpos($modalContainer->getAttribute('class'), $appearClass);
});
}
示例14: getColumnIndex
/**
* @param NodeElement $table
* @param string $columnName
*
* @return int
*
* @throws \Exception If column was not found
*/
private function getColumnIndex(NodeElement $table, $columnName)
{
$rows = $table->findAll('css', 'tr');
if (!isset($rows[0])) {
throw new \InvalidArgumentException('There are no rows!');
}
/** @var NodeElement $firstRow */
$firstRow = $rows[0];
$columns = $firstRow->findAll('css', 'th,td');
foreach ($columns as $index => $column) {
/** @var NodeElement $column */
if (0 === stripos($column->getText(), $columnName)) {
return $index;
}
}
throw new \InvalidArgumentException(sprintf('Column with name "%s" not found!', $columnName));
}
示例15: getRowCell
/**
* @param NodeElement $row
* @param int $position
*
* @throws \InvalidArgumentException
*
* @return NodeElement
*/
protected function getRowCell($row, $position)
{
// $row->findAll('css', 'td') will not work in the case of nested table (like proposals changes)
// because we only need to find the direct children cells
$cells = $row->findAll('xpath', './td');
if (!isset($cells[$position])) {
throw new \InvalidArgumentException(sprintf('Trying to access cell %d of a row which has %d cell(s).', $position + 1, count($cells)));
}
return $cells[$position];
}