如何检查下拉菜单的值?

时间:2018-11-08 16:24:55

标签: angularjs promise protractor bdd

我正在尝试读取(使用量角器和BDD)某些下拉菜单的默认值。为此,我尝试了几行代码,但都没有用。

这是我正在使用的代码,由于某种原因未执行console.log。为什么?

checkDropdownAssignment: function(dropdown,defaultValue) //Function to check the value assigned to a dropdown
{
    let texto=[];

    $$('* option:checked').each(function(element, index) { // Execute this operation for each element of the website
        element.getText().then(function (text) { //Get text of the element in order to compare it with the endpoint afterwards.
        texto.push(index.toString()); // Add one more component to the vector
        texto[index]=text; // Save the text in a variable visible outside of this function.
        console.log(texto[index]);
        });
    });
},

谢谢。

1 个答案:

答案 0 :(得分:0)

尝试一下:

$$('*option:checked').all(by.tagName('option')).getAttribute('label').then(function(value){
 for (var i=0; i<value.length; i++){
  expect(value).toContain(arayOfExpectedResults[i]);
 }
});

在这里,您将获得一个包含下拉列表中所有标签的数组,并将它们与预期结果进行比较,或者以您想要的方式使用该数组。

相关问题