click() 공개 메소드

Clicks on a given link.
public click ( Symfony\Component\DomCrawler\Link $link )
$link Symfony\Component\DomCrawler\Link A Link instance
예제 #1
0
    protected function clickByLocator($link)
    {
        $nodes = $this->match($link);

        if (!$nodes->count()) {
            throw new ElementNotFound($link, 'Link or Button by name or CSS or XPath');
        }

        foreach ($nodes as $node) {
            $tag = $node->nodeName;
            $type = $node->getAttribute('type');
            if ($tag == 'a') {
                $this->crawler = $this->client->click($nodes->first()->link());
                $this->forms = [];
                $this->debugResponse();
                return;
            } elseif(
                ($tag == 'input' && in_array($type, array('submit', 'image'))) ||
                ($tag == 'button' && $type == 'submit'))
            {
                $this->submitFormWithButton($nodes->first());
                $this->debugResponse();
                return;
            }
        }

    }
예제 #2
0
 public function click($link)
 {
     $link = $this->escape($link);
     $anchor = $this->crawler->selectLink($link);
     if (count($anchor)) {
         $this->crawler = $this->client->click($anchor->first()->link());
         $this->debugResponse();
         return;
     }
     $button = $this->crawler->selectButton($link);
     if (count($button)) {
         $this->submitFormWithButton($button);
         $this->debugResponse();
         return;
     }
     \PHPUnit_Framework_Assert::fail("Link or button for '{$link}' was not found");
 }
예제 #3
0
 public function click($link, $context = null)
 {
     $literal = Crawler::xpathLiteral($link);
     if ($context) {
         $this->crawler = $this->match($context);
     }
     $anchor = $this->crawler->filterXPath('.//a[.=' . $literal . ']');
     if (!count($anchor)) {
         $anchor = $this->crawler->selectLink($link);
     }
     if (count($anchor)) {
         $this->crawler = $this->client->click($anchor->first()->link());
         $this->debugResponse();
         return;
     }
     $button = $this->crawler->selectButton($link);
     if (count($button)) {
         $this->submitFormWithButton($button);
         $this->debugResponse();
         return;
     }
     $nodes = $this->match($link);
     if (!$nodes->count()) {
         throw new ElementNotFound($link, 'Link or Button by name or CSS or XPath');
     }
     foreach ($nodes as $node) {
         $tag = $node->nodeName;
         $type = $node->getAttribute('type');
         if ($tag == 'a') {
             $this->crawler = $this->client->click($nodes->first()->link());
             $this->debugResponse();
             return;
         } elseif ($tag == 'input' && in_array($type, array('submit', 'image')) || $tag == 'button' && $type == 'submit') {
             $this->submitFormWithButton($nodes->first());
             $this->debugResponse();
             return;
         }
     }
 }
예제 #4
0
 public function click($link, $context = null)
 {
     $literal = Crawler::xpathLiteral($link);
     if ($context) {
         $this->crawler = $this->match($context);
     }
     $anchor = $this->crawler->filterXPath('.//a[.=' . $literal . ']');
     if (!count($anchor)) {
         $anchor = $this->crawler->selectLink($link);
     }
     if (count($anchor)) {
         $this->crawler = $this->client->click($anchor->first()->link());
         $this->debugResponse();
         return;
     }
     $button = $this->crawler->selectButton($link);
     if (count($button)) {
         $this->submitFormWithButton($button);
         $this->debugResponse();
         return;
     }
     $nodes = $this->match($link);
     if ($nodes->count()) {
         foreach ($nodes as $node) {
             if ($node->nodeName == 'a') {
                 $this->crawler = $this->client->click($nodes->first()->link());
                 $this->debugResponse();
                 return;
             } elseif ($node->nodeName == 'input' && $node->getAttribute('type') == 'submit') {
                 $this->submitFormWithButton($nodes->first());
                 $this->debugResponse();
                 return;
             }
         }
     }
     \PHPUnit_Framework_Assert::fail("Link or button for '{$link}' was not found");
 }
예제 #5
0
 protected function clickByLocator($link)
 {
     $nodes = $this->match($link);
     if (!$nodes->count()) {
         throw new ElementNotFound($link, 'Link or Button by name or CSS or XPath');
     }
     foreach ($nodes as $node) {
         $tag = $node->nodeName;
         $type = $node->getAttribute('type');
         if ($tag === 'a') {
             $this->crawler = $this->client->click($nodes->first()->link());
             $this->forms = [];
             $this->debugResponse();
             break;
         } elseif (in_array($tag, ['input', 'button']) && in_array($type, ['submit', 'image'])) {
             $this->proceedSubmitForm($nodes->parents()->filter('form')->first(), [$nodes->first()->attr('name') => $nodes->first()->attr('value')]);
             break;
         }
     }
 }