Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save fuel-lhartwell/cb0f3ec752d20af0e7d3 to your computer and use it in GitHub Desktop.

Select an option

Save fuel-lhartwell/cb0f3ec752d20af0e7d3 to your computer and use it in GitHub Desktop.
behat autoselect chosen.js
<?php
use Behat\Mink\Exception\ElementNotFoundException;
/**
* @Given /^I select "([^"]*)" from "([^"]*)" chosen\.js autoselect box$/
*/
public function iSelectFromChosenJAutoselectBox($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->getSession()->getDriver(), 'form field', 'id|name|label|value', $select);
}
$id = $field->getAttribute('id');
$javascript = "var select = jQuery('#$id > option:contains(\'$option\')').val();
jQuery('#$id').val(select).change().trigger('chosen:updated');";
$this->getSession()->executeScript($javascript);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment