AngularJS + Protractor How to select Dropdown option based on its text not value -
i want click on item it's text , not it's value dropdown box.
i found great post : https://coderwall.com/p/tjx5zg doesn't work expected, search continue forever after match found , not clicking item,
if have better example (a working one) or can fix code , make work,
i apperciate.
this code dan haller post used (all rights reserved 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 select item function can use this:
var browser = protractor.getinstance(); browser.selectoption = selectoption.bind(browser); browser.selectoption(protractor.by.id('my-dropdown'), 'my value');
this function selects 3rd option of select box.
function selectdropdownbynumber(element, index, milliseconds) { element.findelements(by.tagname('option')) .then(function(options) { options[index].click(); }); if (typeof milliseconds !== 'undefined') { browser.sleep(milliseconds); } } var myselect = $('#my-dropdown'); selectdropdownbynumber(myselect, 2);
more info can found here - http://qainsight.blogspot.fr/2014/04/select-dropdown-value-in-protractor-js.html
Comments
Post a Comment