Skip to content

Instantly share code, notes, and snippets.

@mouton-rebelle
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save mouton-rebelle/9503898 to your computer and use it in GitHub Desktop.

Select an option

Save mouton-rebelle/9503898 to your computer and use it in GitHub Desktop.
<?php
// (...)
/**
* SELECT AN ITEM FROM A CHOSEN SELECTOR
*
* @Given /^I select item "([^"]*)" from chosen "([^"]*)"$/
*/
public function iSelectItemFromChosen($text, $selector)
{
$this->getSession()->executeScript('
$("'.$selector.' option").each(function(i){
if ($(this).text() == "'.$text.'"){
$(this).attr("selected","selected");
}
});
$("'.$selector.'").trigger("chosen:updated").trigger("change");
');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment