量角器,下拉列表的设定值

时间:2016-10-24 13:38:18

标签: testing protractor

您好我有一个注册表单,使用ngRepeat创建出生日期的月份表单字段。 在我的量角器测试中,我希望能够设置/选择月份的值。就像使用sendKeys函数填充输入字段一样。

斯蒂芬

1 个答案:

答案 0 :(得分:0)

解决方案01

Select based on drop-down values attribute details
public selectOptionByValue(element: ElementArrayFinder,valueToSelect: string) : void{
        let clickedIndex: number;
        element.first().$$('option').filter(function(elem, index) {
            return elem.getAttribute("value").then(function(value) {
                if (value === valueToSelect) {
                    elem.click();
                    console.log('Yes ! Found option is:' + value);
                }
                return value === valueToSelect;
            });
        }).then(function (bool) {

        }).catch(function (err) {
            console.log('Ooops ! Error... '+err.message);
        });
    }

解决方案02

Select based on drop-down visible text details
public selectOptionByText(element: ElementArrayFinder,optionToSelect: string) : void{
        let clickedIndex: number;
        element.first().$$('option').filter(function(elem, index) {
            return elem.getText().then(function(text) {
                    if (text === optionToSelect) {
                        elem.click();
                        console.log('Yes ! Found option is:' + text);
                    }
                return text === optionToSelect;
            });
        }).then(function (bool) {

        }).catch(function (err) {
            console.log('Ooops ! Error... '+err.message);
        });
    }