当前位置: 首页>>代码示例>>PHP>>正文


PHP Crawler::xpathLiteral方法代码示例

本文整理汇总了PHP中Symfony\Component\DomCrawler\Crawler::xpathLiteral方法的典型用法代码示例。如果您正苦于以下问题:PHP Crawler::xpathLiteral方法的具体用法?PHP Crawler::xpathLiteral怎么用?PHP Crawler::xpathLiteral使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\DomCrawler\Crawler的用法示例。


在下文中一共展示了Crawler::xpathLiteral方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: initialize

 /**
  * Adds form elements related to this form.
  *
  * Creates an internal copy of the submitted 'button' element and
  * the form node or the entire document depending on whether we need
  * to find non-descendant elements through HTML5 'form' attribute.
  */
 private function initialize()
 {
     $this->fields = new FormFieldRegistry();
     $xpath = new \DOMXPath($this->node->ownerDocument);
     // add submitted button if it has a valid name
     if ('form' !== $this->button->nodeName && $this->button->hasAttribute('name') && $this->button->getAttribute('name')) {
         if ('input' == $this->button->nodeName && 'image' == strtolower($this->button->getAttribute('type'))) {
             $name = $this->button->getAttribute('name');
             $this->button->setAttribute('value', '0');
             // temporarily change the name of the input node for the x coordinate
             $this->button->setAttribute('name', $name . '.x');
             $this->set(new Field\InputFormField($this->button));
             // temporarily change the name of the input node for the y coordinate
             $this->button->setAttribute('name', $name . '.y');
             $this->set(new Field\InputFormField($this->button));
             // restore the original name of the input node
             $this->button->setAttribute('name', $name);
         } else {
             $this->set(new Field\InputFormField($this->button));
         }
     }
     // find form elements corresponding to the current form
     if ($this->node->hasAttribute('id')) {
         // corresponding elements are either descendants or have a matching HTML5 form attribute
         $formId = Crawler::xpathLiteral($this->node->getAttribute('id'));
         $fieldNodes = $xpath->query(sprintf('descendant::input[@form=%s] | descendant::button[@form=%s] | descendant::textarea[@form=%s] | descendant::select[@form=%s] | //form[@id=%s]//input[not(@form)] | //form[@id=%s]//button[not(@form)] | //form[@id=%s]//textarea[not(@form)] | //form[@id=%s]//select[not(@form)]', $formId, $formId, $formId, $formId, $formId, $formId, $formId, $formId));
         foreach ($fieldNodes as $node) {
             $this->addField($node);
         }
     } else {
         // do the xpath query with $this->node as the context node, to only find descendant elements
         // however, descendant elements with form attribute are not part of this form
         $fieldNodes = $xpath->query('descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)]', $this->node);
         foreach ($fieldNodes as $node) {
             $this->addField($node);
         }
     }
     if ($this->baseHref && '' !== $this->node->getAttribute('action')) {
         $this->currentUri = $this->baseHref;
     }
 }
开发者ID:saj696,项目名称:pipe,代码行数:48,代码来源:Form.php

示例2: findCheckable

 /**
  * @param $context
  * @param $radioOrCheckbox
  * @param bool $byValue
  * @return mixed|null
  */
 protected function findCheckable($context, $radioOrCheckbox, $byValue = false)
 {
     if ($radioOrCheckbox instanceof WebDriverElement) {
         return $radioOrCheckbox;
     }
     if (is_array($radioOrCheckbox) or $radioOrCheckbox instanceof WebDriverBy) {
         return $this->matchFirstOrFail($this->webDriver, $radioOrCheckbox);
     }
     $locator = Crawler::xpathLiteral($radioOrCheckbox);
     if ($context instanceof WebDriverElement && $context->getTagName() === 'input') {
         $contextType = $context->getAttribute('type');
         if (!in_array($contextType, ['checkbox', 'radio'], true)) {
             return null;
         }
         $nameLiteral = Crawler::xPathLiteral($context->getAttribute('name'));
         $typeLiteral = Crawler::xPathLiteral($contextType);
         $inputLocatorFragment = "input[@type = {$typeLiteral}][@name = {$nameLiteral}]";
         $xpath = Locator::combine("ancestor::form//{$inputLocatorFragment}[(@id = ancestor::form//label[contains(normalize-space(string(.)), {$locator})]/@for) or @placeholder = {$locator}]", "ancestor::form//label[contains(normalize-space(string(.)), {$locator})]//{$inputLocatorFragment}");
         if ($byValue) {
             $xpath = Locator::combine($xpath, "ancestor::form//{$inputLocatorFragment}[@value = {$locator}]");
         }
     } else {
         $xpath = Locator::combine("//input[@type = 'checkbox' or @type = 'radio'][(@id = //label[contains(normalize-space(string(.)), {$locator})]/@for) or @placeholder = {$locator}]", "//label[contains(normalize-space(string(.)), {$locator})]//input[@type = 'radio' or @type = 'checkbox']");
         if ($byValue) {
             $xpath = Locator::combine($xpath, "//input[@type = 'checkbox' or @type = 'radio'][@value = {$locator}]");
         }
     }
     $els = $context->findElements(WebDriverBy::xpath($xpath));
     if (count($els)) {
         return reset($els);
     }
     $els = $context->findElements(WebDriverBy::xpath(str_replace('ancestor::form', '', $xpath)));
     if (count($els)) {
         return reset($els);
     }
     $els = $this->match($context, $radioOrCheckbox);
     if (count($els)) {
         return reset($els);
     }
     return null;
 }
开发者ID:neronmoon,项目名称:Codeception,代码行数:47,代码来源:WebDriver.php

示例3: initialize

 /**
  * Adds form elements related to this form.
  *
  * Creates an internal copy of the submitted 'button' element and
  * the form node or the entire document depending on whether we need
  * to find non-descendant elements through HTML5 'form' attribute.
  */
 private function initialize()
 {
     $this->fields = new FormFieldRegistry();
     $document = new \DOMDocument('1.0', 'UTF-8');
     $xpath = new \DOMXPath($document);
     $root = $document->appendChild($document->createElement('_root'));
     // add submitted button if it has a valid name
     if ($this->button->hasAttribute('name') && $this->button->getAttribute('name')) {
         $this->set(new Field\InputFormField($document->importNode($this->button, true)));
     }
     // find form elements corresponding to the current form
     if ($this->node->hasAttribute('id')) {
         // traverse through the whole document
         $node = $document->importNode($this->node->ownerDocument->documentElement, true);
         $root->appendChild($node);
         // corresponding elements are either descendants or have a matching HTML5 form attribute
         $formId = Crawler::xpathLiteral($this->node->getAttribute('id'));
         $fieldNodes = $xpath->query(sprintf('descendant::input[@form=%s] | descendant::button[@form=%s] | descendant::textarea[@form=%s] | descendant::select[@form=%s] | //form[@id=%s]//input[not(@form)] | //form[@id=%s]//button[not(@form)] | //form[@id=%s]//textarea[not(@form)] | //form[@id=%s]//select[not(@form)]', $formId, $formId, $formId, $formId, $formId, $formId, $formId, $formId), $root);
         foreach ($fieldNodes as $node) {
             $this->addField($node);
         }
     } else {
         // parent form has no id, add descendant elements only
         $node = $document->importNode($this->node, true);
         $root->appendChild($node);
         // descendant elements with form attribute are not part of this form
         $fieldNodes = $xpath->query('descendant::input[not(@form)] | descendant::button[not(@form)] | descendant::textarea[not(@form)] | descendant::select[not(@form)]', $root);
         foreach ($fieldNodes as $node) {
             $this->addField($node);
         }
     }
 }
开发者ID:Thomvh,项目名称:turbine,代码行数:39,代码来源:Form.php

示例4: strictMatch

 /**
  * @param array $by
  * @throws TestRuntime
  * @return Crawler
  */
 protected function strictMatch(array $by)
 {
     $type = key($by);
     $locator = $by[$type];
     switch ($type) {
         case 'id':
             return $this->crawler->filter("#{$locator}");
         case 'name':
             return @$this->crawler->filterXPath(sprintf('.//*[@name=%s]', Crawler::xpathLiteral($locator)));
         case 'css':
             return $this->crawler->filter($locator);
         case 'xpath':
             return @$this->crawler->filterXPath($locator);
         case 'link':
             return @$this->crawler->filterXPath(sprintf('.//a[.=%s]', Crawler::xpathLiteral($locator)));
         case 'class':
             return $this->crawler->filter(".{$locator}");
         default:
             throw new TestRuntime("Locator type '{$by}' is not defined. Use either: xpath, css, id, link, class, name");
     }
 }
开发者ID:Eli-TW,项目名称:Codeception,代码行数:26,代码来源:InnerBrowser.php

示例5: dontSeeLink

 public function dontSeeLink($text, $url = null)
 {
     $links = $this->crawler->selectLink($text);
     if ($url) {
         $links = $links->filterXPath(sprintf('descendant-or-self::a[contains(@href, %s)]', Crawler::xpathLiteral($this->escape($url))));
     }
     $this->assertDomNotContains($links, 'a');
 }
开发者ID:lenninsanchez,项目名称:donadores,代码行数:8,代码来源:Framework.php

示例6: findCheckable

 /**
  * @param $context
  * @param $radio_or_checkbox
  * @param bool $byValue
  * @return mixed|null
  */
 protected function findCheckable($context, $radio_or_checkbox, $byValue = false)
 {
     if ($radio_or_checkbox instanceof \WebDriverElement) {
         return $radio_or_checkbox;
     }
     if (is_array($radio_or_checkbox) or $radio_or_checkbox instanceof \WebDriverBy) {
         return $this->matchFirstOrFail($this->webDriver, $radio_or_checkbox);
     }
     $locator = Crawler::xpathLiteral($radio_or_checkbox);
     $xpath = Locator::combine("//input[./@type = 'checkbox'][(./@id = //label[contains(normalize-space(string(.)), {$locator})]/@for) or ./@placeholder = {$locator}]", "//label[contains(normalize-space(string(.)), {$locator})]//.//input[./@type = 'checkbox']", "//input[./@type = 'radio'][(./@id = //label[contains(normalize-space(string(.)), {$locator})]/@for) or ./@placeholder = {$locator}]", "//label[contains(normalize-space(string(.)), {$locator})]//.//input[./@type = 'radio']");
     if ($byValue) {
         $xpath = Locator::combine($xpath, "//input[./@type = 'checkbox'][./@value = {$locator}]", "//input[./@type = 'radio'][./@value = {$locator}]");
     }
     /** @var $context \WebDriverElement  * */
     $els = $context->findElements(\WebDriverBy::xpath($xpath));
     if (count($els)) {
         return reset($els);
     }
     $els = $this->match($context, $radio_or_checkbox);
     if (count($els)) {
         return reset($els);
     }
     return null;
 }
开发者ID:Eli-TW,项目名称:Codeception,代码行数:30,代码来源:WebDriver.php

示例7: initialize

 private function initialize()
 {
     $this->fields = new FormFieldRegistry();
     $document = new \DOMDocument('1.0', 'UTF-8');
     $node = $document->importNode($this->node, true);
     $button = $document->importNode($this->button, true);
     $root = $document->appendChild($document->createElement('_root'));
     $root->appendChild($node);
     $root->appendChild($button);
     $xpath = new \DOMXPath($document);
     // add descendant elements to the form
     $fieldNodes = $xpath->query('descendant::input | descendant::button | descendant::textarea | descendant::select', $root);
     foreach ($fieldNodes as $node) {
         $this->addField($node, $button);
     }
     // find form elements corresponding to the current form by the HTML5 form attribute
     if ($this->node->hasAttribute('id')) {
         $formId = Crawler::xpathLiteral($this->node->getAttribute('id'));
         $xpath = new \DOMXPath($this->node->ownerDocument);
         $fieldNodes = $xpath->query(sprintf('descendant::input[@form=%s] | descendant::button[@form=%s] | descendant::textarea[@form=%s] | descendant::select[@form=%s]', $formId, $formId, $formId, $formId));
         foreach ($fieldNodes as $node) {
             $this->addField($node, $button);
         }
     }
 }
开发者ID:acappel01,项目名称:opencall,代码行数:25,代码来源:Form.php

示例8: dontSeeLink

 public function dontSeeLink($text, $url = null)
 {
     $links = $this->crawler->selectLink($this->escape($text));
     if (!$url) {
         \PHPUnit_Framework_Assert::assertEquals(0, $links->count(), "'{$text}' on page");
     }
     $links->filterXPath(sprintf('descendant-or-self::a[contains(@href, "%s")]', Crawler::xpathLiteral(' ' . $this->escape($url) . ' ')));
     \PHPUnit_Framework_Assert::assertEquals(0, $links->count());
 }
开发者ID:BatVane,项目名称:Codeception,代码行数:9,代码来源:Framework.php


注:本文中的Symfony\Component\DomCrawler\Crawler::xpathLiteral方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。