首页 > 解决方案 > 使用 element.all 遍历表时量角器抛出 StaleElementReferenceError

问题描述

我有量角器测试,它将在一个有 6 列的表上进行迭代。我正在使用 element.all 在表上进行迭代,然后在第一列中搜索特定文本。如果匹配,请检查第 6 列中的状态,如果设置为激活,单击匹配的行将其转到另一个页面,执行操作,返回表页面,在同一个表上重复并检查该特定文本并再次验证最终状态为激活。

测试运行良好,但失败并出现以下错误。

StaleElementReferenceError: stale element reference: element is not attached to the page document

element.all(by.css('tbody tr')).each(function(item){
    var count=0;
    var pass=0;
    //TEST VALUES BELOW
    var appNameCreated="Test App 534";
    //TEST VALUES ABOVE
    item.element(by.css('td:nth-child(1)')).getText().then(function(appname){
        if(appname==appNameCreated){
            console.log(appname,appNameCreated);
            item.element(by.css('td:nth-child(6)')).getText().then(function(result){
                pass += 1;
                console.log(result);
                if (result=="Activated"){
                //if (result==data.resultSubmit){
                    item.element(by.css('td:nth-child(1)')).element(by.css('a')).click().then(function(){
                    browser.sleep(4000);
                    });
                    element(by.id("btnTab3")).element(by.xpath('span')).click();
                    browser.wait(EC.visibilityOf(element(by.xpath('/html/body/gft-root/section/div[2]/app-onboard-list/div[4]/div[3]/table/tbody/tr[1]/td[1]'))),15000);
                    element(by.id("button-basic")).click();
                    element.all(by.css('ul[class="dropdown-menu"]')).each(function(item1){
                        item1.element(by.css('li:nth-child(7)')).element(by.css('a')).click();
                    })
                    element.all(by.css('tbody tr')).each(function(item2){
                        item2.element(by.css('td:nth-child(1)')).getText().then(function(appname1){
                            if(appname1==appNameCreated){
                                item2.element(by.css('td:nth-child(6)')).getText().then(function(resultFin){
                                    console.log(resultFin);
                                    browser.actions().mouseMove(item2.element(by.css('td:nth-child(1)'))).perform();
                                    expect(resultFin).toBe(data.resultFinal);
                                })
                            }   
                        })
                    })
                }           
            })
        }
    })
})

标签: javascriptjasmineprotractor

解决方案


推荐阅读