Skip to content

Instantly share code, notes, and snippets.

@acouch
Created March 26, 2014 14:33
Show Gist options
  • Save acouch/9784746 to your computer and use it in GitHub Desktop.
Save acouch/9784746 to your computer and use it in GitHub Desktop.
Click on a leaflet map icon in behat using a custom assumption
// Leaflet icons don't haave ids (at least the ones I'm using). Here we can click them by the z-index which is
// the only unique id.
/**
* Click on map icon as identified by its z-index.
*
* @Given /^I click map icon number "([^"]*)"$/
*/
public function iClickMapIcon($num) {
$session = $this->getSession();
$element = $session->getPage()->find(
'xpath',
$session->getSelectorsHandler()->selectorToXpath('xpath', '//img[contains(@style,"z-index: ' . $num . '")]')
);
if (null === $element) {
throw new \InvalidArgumentException(sprintf('Cannot find map icon: "%s"', $num));
}
$element->click();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment