/**
  * Returns DOMElement from crawler instance.
  *
  * @param Crawler $crawler
  *
  * @return \DOMElement
  *
  * @throws DriverException when the node does not exist
  */
 private function getCrawlerNode(Crawler $crawler)
 {
     $node = null;
     if ($crawler instanceof \Iterator) {
         // for symfony 2.3 compatibility as getNode is not public before symfony 2.4
         $crawler->rewind();
         $node = $crawler->current();
     } else {
         $node = $crawler->getNode(0);
     }
     if (null !== $node) {
         return $node;
     }
     throw new DriverException('The element does not exist');
 }
 /**
  * @param $content string
  *
  * @return string
  */
 private function removeLastItem($content)
 {
     $document = new \DOMDocument('1.0', \Yii::$app->charset);
     $crawler = new Crawler();
     $crawler->addHTMLContent($content, \Yii::$app->charset);
     $root = $document->appendChild($document->createElement('_root'));
     $crawler->rewind();
     $root->appendChild($document->importNode($crawler->current(), true));
     $domxpath = new \DOMXPath($document);
     $crawlerInverse = $domxpath->query(CssSelector::toXPath($this->widgetItem . ':last-child'));
     foreach ($crawlerInverse as $key => $elementToRemove) {
         $parent = $elementToRemove->parentNode;
         $parent->removeChild($elementToRemove);
     }
     $crawler->clear();
     $crawler->add($document);
     return $crawler->filter('body')->eq(0)->html();
 }
示例#3
0
 /**
  * Iterator interface implementation
  *
  * @group Iterator
  */
 function rewind()
 {
     $this->crawler->rewind();
 }
示例#4
0
 /**
  * Returns DOMElement from crawler instance.
  *
  * @param Crawler $crawler
  *
  * @return \DOMElement
  *
  * @throws DriverException when the node does not exist
  */
 private function getCrawlerNode(Crawler $crawler)
 {
     $crawler->rewind();
     $node = $crawler->current();
     if (null !== $node) {
         return $node;
     }
     throw new DriverException('The element does not exist');
 }