diff --git a/src/Extensions/Selenium.php b/src/Extensions/Selenium.php index 5fd668d..b4e2a9b 100644 --- a/src/Extensions/Selenium.php +++ b/src/Extensions/Selenium.php @@ -92,7 +92,11 @@ public function click($name) try { $link = $this->findByBody($name)->click(); } catch (InvalidArgumentException $e) { - $link = $this->findByNameOrId($name)->click(); + try { + $link = $this->findByCss($name)->click(); + } catch (InvalidArgumentException $e) { + $link = $this->findByNameOrId($name)->click(); + } } $this->updateCurrentUrl(); @@ -141,6 +145,21 @@ protected function findByNameOrId($name, $element = '*') } } + /** + * Filter according to an element's css attribute + * For example ->click('a[href^="/item/'.$item->slug.'"]') + * + * @param string $selector + * @return Crawler + */ + protected function findByCss($selector){ + try{ + return $this->session->element('css selector', $selector); + } catch (NoSuchElement $e) { + throw new InvalidArgumentException('No Css element exists.'); + } + } + /** * Find an element by its "value" attribute. *