Skip to content

Instantly share code, notes, and snippets.

@javigomez
Created November 10, 2015 11:25
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javigomez/33c03419b729674bdb77 to your computer and use it in GitHub Desktop.
Save javigomez/33c03419b729674bdb77 to your computer and use it in GitHub Desktop.
Select option in Selectize JS library with Selenium and Codeception
/**
* Selects an option in a Chosen Selector based on its label
*
* @return void
*/
public function selectOptionInSelectize($label, $option)
{
$I = $this;
$I->waitForJS("return jQuery(\"label:contains('$label')\");");
$selectID = $I->executeJS("return jQuery(\"label:contains('$label')\").attr(\"for\");");
$selectizeSelectID = $selectID . '_selectize';
$dropwdownId = $selectID . '_selectize_options';
$I->waitForElement(['id' => $selectizeSelectID], 60);
$I->comment("I open the $label chosen selector");
$I->click(['xpath' => "//div[@id='$selectizeSelectID']/div"]);
$I->waitForElement(['xpath' => "//div[@id='$selectizeSelectID']//input"], 60);
$I->pressKey(['xpath' => "//div[@id='$selectizeSelectID']//input"], \Facebook\WebDriver\WebDriverKeys::BACKSPACE);
$I->wait(1);
$I->fillField(['xpath' => "//div[@id='$selectizeSelectID']//input"], $option);
$I->waitForElement(['xpath' => "//div[@id='$dropwdownId']/div[@class='selectize-dropdown-content']/div[@data-title='$option']"], 60);
$I->click(['xpath' => "//div[@id='$dropwdownId']/div[@class='selectize-dropdown-content']/div[@data-title='$option']"]);
// Gives time to selectize to close
$I->wait(1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment