量角器无法选择下拉选项 [英] Protractor unable to select dropdown option

查看:51
本文介绍了量角器无法选择下拉选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在做量角器测试,但我的测试有问题.我的 ionic 应用程序确实有一个带有型号名称的下拉菜单,我尝试使用型号名称访问它并且它可以工作,但问题是它无法选择我需要从该下拉选项中选择的确切选项.它只选择第一个?我写了这样的量角器语法.

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

但是此代码选择的不是值 59,而是值 0,这是默认选项.有谁能帮帮我吗?

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

推荐答案

您应该添加 html 源以方便回答.

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

这篇关于量角器无法选择下拉选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆