Created
August 17, 2013 04:55
-
-
Save delphian/6255330 to your computer and use it in GitHub Desktop.
Returns the first element found from Mink's NodeElement::findAll() request.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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