Protractor unable to select dropdown option

一世执手 提交于 2019-12-25 06:01:57

问题


Hi I have been doing protractor test and I'm having a problem with my tests. My ionic app do have a drop down having a model name and I tried to access it using the model name and it works but the problem is it can not select the exact option that i need to select from that dropdown option. It selects only the first one? I wrote the protractor syntax like this.

element(by.model('generalPowerOfAttorney.grantorGeneralPowerOfAttorneyForm.region')).$('[value="59"]').click();

But this code selects not the value 59 rather value 0 which is the default option. Is there anyone who could help me?


回答1:


You should add the html source to facilitate the answer.

You can use the filter method in order to get the correct element clicked.

var elements = element.all(by.model('generalPowerOfAttorney.grantorGeneralPowerOfAttorneyForm.region'));

elements.filter(function(elem, index) {
    return elem.getText().then(function(text) {
        return text === 'value="59"';
    });
}).then(function(filteredElem){
    if(filteredElem[0] !== undefined){
        filteredElem[0].click();
    }
    else {
        throw 'element not found'
    }
});


来源:https://stackoverflow.com/questions/33412256/protractor-unable-to-select-dropdown-option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!