Protractor clicking through an array of elements

前端 未结 3 1026
陌清茗
陌清茗 2021-01-20 01:13

I\'m quite new to e2e testing and in using protractor / jasmine framework. I know how to get an array of elements and also how to click on an anchor. But how would / is it e

3条回答
  •  野的像风
    2021-01-20 01:53

    Solution 01

    public findSpecificElementAndClick(element: ElementArrayFinder,expected: number){
            let clickedIndex: number = -1;
            element.filter(function (elementItem, index) {
                clickedIndex++;
                if(index === (expected-1)){
                    element.get(clickedIndex).click();
                    return true;
                }
            }).then(function (bool) {
    
            }).catch(function (err) {
                throw new FrameworkException('Ooops ! Error... '+err.message);
            });
        }
    

    Solution 02

    public findTextAndClick(element: ElementArrayFinder,expected: string) {
            let clickedIndex: number = -1;
            let status :boolean = false;
            element.filter(function (elementItem, index) {
                return elementItem.getText().then(function (text) {
                    if(text === expected) {
                        clickedIndex = index;
                        status = true;
                        return true;
                    }
                });
            }).then(function (bool) {
                if(!status){
                    throw new ApplicationException("Ooops ! Couldn't found "+expected+" Record ...");
                }else{
                    element.get(clickedIndex).click();
                }
            }).catch(function (err) {
                throw new FrameworkException('Ooops ! Error... '+err.message);
            });
        }
    

提交回复
热议问题