【问题标题】:Protractor - How do I return an element by the text contained within a child element?Protractor - 如何通过子元素中包含的文本返回元素?
【发布时间】:2018-10-12 21:13:11
【问题描述】:

想知道我是否可以得到一些帮助。当我声明这个 webelement 引用时,我返回了一个 <tr> 元素数组

locationAuditsBySourceListViewTableRows : { //returns an array
    get : function(){
        return this.locationAuditsBySourceListViewTable.all(by.repeater('audit in location.displayedProfileAudits'));
    }
}, 

在其中一个<tr> 元素中是一个跨度,其中包含指定我要选择的行的文本。

我正在使用的当前框架有一些类似的方法,我试图为我的目的对其进行重构,但是这段代码失败了:

locationAuditsListViewRowBySource : {
    value : function(sourceName){
        return this.locationAuditsBySourceListViewTableRows.filter(elem => { 
            //elem - placeholder as we iterate  through each element within the locationAuditsBySourceListViewTableRows array           
            return elem.element(by.css(".source-name.ng-binding")).getText().then((val) => {
                return val.toLowerCase() == sourceName.toLowerCase();
            }); 
        }).first();             
    }
},

我的感觉是我尝试在表格行中引用跨度的方式不正确(调用是在 .filter() 方法中进行的):

        return elem.element(by.css(".source-name.ng-binding")).getText().then((val) => {

这是步骤定义本身:

Then(/^I should see that location audit for source row: "([^"]*)" has a label for the source$/, function (sourceName, callback) {
    browser.wait(EC.visibilityOf(listingsPageObj.locationAuditsBySourceListViewContainer), timeouts.EC_TIMEOUT).then(() => {
        browser.wait(EC.visibilityOf(listingsPageObj.locationAuditsBySourceListViewTable), timeouts.EC_TIMEOUT).then(() => {
            browser.wait(() => {
                return listingsPageObj.locationAuditsBySourceListViewTableHeaders.count().then(cnt => (cnt > 0)); //which means that there are audit results displayed
            }).then(() => {
                //find a row in the list of displayed audits
                var tableRow = listingsPageObj.locationAuditsListViewRowBySource(sourceName);                                       
            });
        });
    });
});

任何人都可以帮助我/引导我朝着正确的方向前进吗?

谢谢。

【问题讨论】:

    标签: angularjs protractor automated-tests ui-automation qa


    【解决方案1】:

    elem.element(by.css(".source-name.ng-binding")).getText()的用法是对的。

    但对代码进行一些小的改动会更好:

    return val.trim().toLowerCase() == sourceName.trim().toLowerCase();
    
    return listingsPageObj.locationAuditsBySourceListViewTableHeaders
              .count().then(cnt => {return cnt > 0;}) // I think you need return
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-24
      • 2020-09-27
      • 1970-01-01
      • 1970-01-01
      • 2021-08-22
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      相关资源
      最近更新 更多