Created
November 10, 2015 11:25
-
-
Save javigomez/33c03419b729674bdb77 to your computer and use it in GitHub Desktop.
Select option in Selectize JS library with Selenium and Codeception
This file contains 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
/** | |
* 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