Created
November 16, 2015 10:20
-
-
Save ratajczak/bb19f1773f3c6e8e96b6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* @Given /^I select "([^"]*)" from "([^"]*)" chosen\.js select box$/ | |
*/ | |
public function iSelectFromChosenJsSelectBox($option, $select) { | |
$select = $this->fixStepArgument($select); | |
$option = $this->fixStepArgument($option); | |
$page = $this->getSession()->getPage(); | |
$field = $page->findField($select, true); | |
if (null === $field) { | |
throw new ElementNotFoundException($this->getDriver(), 'form field', 'id|name|label|value', $select); | |
} | |
$id = $field->getAttribute('id'); | |
$opt = $field->find('named', array('option', $option)); | |
$val = $opt->getValue(); | |
$javascript = "jQuery('#$id').val('$val'); | |
jQuery('#$id').trigger('chosen:updated'); | |
jQuery('#$id').trigger('change');"; | |
$this->getSession()->executeScript($javascript); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much. Works like a charm even in a headless environment.