Skip to content

Instantly share code, notes, and snippets.

@delphian
Created August 17, 2013 04:55
Show Gist options
  • Save delphian/6255330 to your computer and use it in GitHub Desktop.
Save delphian/6255330 to your computer and use it in GitHub Desktop.
Returns the first element found from Mink's NodeElement::findAll() request.
/**
* Select the first CSS element returned by findAll query.
*
* @param string $selector.
* CSS selector.
*
* @return NodeElement
* Or throws error if unable to locate.
*/
protected function elementSelectFirst($selector)
{
$session = $this->getSession();
$elements = $session->getPage()->findAll('css', $selector);
if (is_array($elements)) {
$element = array_shift($elements);
}
if (null === $element) {
throw new \InvalidArgumentException(sprintf('Could not locate css selector: "%s"', $selector));
}
return $element;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment