Testing with protractor using ui-select

ぃ、小莉子 提交于 2019-12-04 06:15:58

I have found the solution here

this.country = element(by.model('datiAnagrafici.countryOfBirth'));
this.selectCountry = this.country.element(by.css('.ui-select-search'));

then in the fill form method is almost as alecxe said:

this.country.click();
this.selectCountry.sendKeys('Italy');

You can also wrap an ui-select with a function like that:

    function UiSelect(elem) {
        var self = this;

        self._input = elem;
        self._selectInput = self._input.element(by.css('.ui-select-search'));
        self._choices = self._input.all(by.css('.ui-select-choices .ui-select-choices-row-inner'));

        self.sendKeys = function(val) {
            self._input.click();
            self._selectInput.clear();
            return self._selectInput.sendKeys(val);
        };

        self.pickChoice = function(index){
            browser.waitForAngular();
            expect(self._choices.count()).not.toBeLessThan(index + 1);
            return self._choices.get(index).click();
        };
    };

Now it's easier to manipulate any ui-select input:

var input = new UiSelect(element(by.model('datiAnagrafici.countryOfBirth')));
input.sendKeys('IT'); 
input.pickChoice(0); // Pick choice with index 0 when searching for 'IT'. 

Before sending keys, click the ui-select element:

this.country.click();
this.country.sendKeys('IT');

While I couldn't get sniper87's answer to work for me, by playing around with the css this worked correctly:

element(by.css('div.ui-select-container div.ui-select-match span.ui-select-input')).click();
element(by.css('div.ui-select-container .ui-select-search')).sendKeys('foo');;

after clicking the ui-select element and filling the input, you should then select result by adding this :

element.all(by.css('.ui-select-choices-row-inner span')).first().click();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!