1
votes

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

2
you made a typo. It should be getText(), rather than gettext()yong

2 Answers

2
votes
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

0
votes

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();
}