I want to click on item by it's text and not by it's value from dropdown box.
i found this great post : https://coderwall.com/p/tjx5zg but it doesn't work as expected, the search continue forever after match was found and it is not clicking the item,
if someone have better example (a working one) or can fix this code and make it work,
i will apperciate.
This is the code Dan Haller from the post used (all rights reserved to him)
function selectOption(selector, item){
var selectList, desiredOption;
selectList = this.findElement(selector);
selectList.click();
selectList.findElements(protractor.By.tagName('option'))
.then(function findMatchingOption(options){
options.some(function(option){
option.getText().then(function doesOptionMatch(text){
if (item === text){
desiredOption = option;
return true;
}
});
});
})
.then(function clickOption(){
if (desiredOption){
desiredOption.click();
}
});
}
This is a select item function that I can use like this:
var browser = protractor.getInstance();
browser.selectOption = selectOption.bind(browser);
browser.selectOption(protractor.By.id('my-dropdown'), 'My Value');