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); | |
} |
Thank you so much. Works like a charm even in a headless environment.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ratajczak I updated your example to fix the Exception handling here: https://gist.github.com/generalconsensus/eff13d8d572327024baf