Reputation: 11
I got the count of the values inside the drop down and trying to click on each option one by one and verify something but I couldn't click on options.
let button = $('[href* ='something']');
let dropdown = element(by.id('someid'));
let options = dropdown.all(by.tagname('option'));
button.click();
options.then(function (items) {
console.log(items.length);
for (let i = 0; i < items.length; i++) {
items[i].gettext().then(function (text: any) {
items[i].click();
});
}
});
Its showing me error as gettext() is not a function and I tried getattribute('value') also still no use,Can someone help on this please
Upvotes: 1
Views: 627
Reputation: 1442
let button = $('[href* ='something']');
let dropdown = element(by.id('someid'));
let options = dropdown.all(by.tagname('option'));
button.click();
for (let i = 0; i < options.count(); i++) {
options.get(i).getText().then(function (text: any) {
options.get(i).click();
});
}
Hope it helps you
Since items
is array of elements, you have to use get(//element position in the array)
to access the particular element in the array.
refer https://www.protractortest.org/#/api?view=ElementArrayFinder.prototype.get
Upvotes: 2
Reputation: 14
Not sure when the option is going get generated in the DOM. In the for loop try
browser.driver.findElements(element(by.css('#someid option')).then(elms => {
return elms[i].click();
}
Upvotes: 0