如何获取选择元素的选项值 [英] How to get option value of select element
本文介绍了如何获取选择元素的选项值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用量角器获取选择元素的选项值.但是,我找不到选项元素.
I am trying to get the option value of a select element using Protractor. However, I'm not able to find the option element.
HTML
<select ng-options="opions.c as options.n for option in options" ng-model="model">
<option value="0">Option 1</option>
<option value="1">Option 2</option>
</select>
规格文件
describe('testing select option', function() {
it('', function() {
ptor = protractor.getInstance();
//This will not get the option required
ptor.findElement(protractor.By.binding('model'));
});
});
我似乎找不到获取选项值的方法,因为我还没有找到一个我可以使用但不提供异常或错误消息的函数.
I cannot seem to find a way to grab the option value as I haven't found a function that I can use that doesn't give and exception or error message.
有人知道如何解决这个问题吗?
Does anyone know how to resolve this issue?
推荐答案
好吧,我现在已经能够弄清楚如何用量角器抓取选项元素了.
ok again I have now been able to figure out how to grab the option element with protractor.
下面的示例代码显示了如何完成此操作.
the example code below shows how to accomplish this.
ptor.findElement(protractor.By.css('select option:nth-child(value of the option you require IE: the number)')).click();
这篇关于如何获取选择元素的选项值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文