【问题标题】:Protractor/Js - Unable to get accurate table row and column count量角器/Js - 无法获得准确的表格行数和列数
【发布时间】:2018-10-13 04:10:41
【问题描述】:

我正在尝试使用 Protractor/Js 验证表中的行数和列数。

我尝试了以下 四个 功能,但返回的结果不准确。我相信我的定位器可能是错误的 - '.tsc_table_s13'

行:

 $(locator).all(by.xpath('.//tbody/tr')).count().then(function (data) {
            expect(data).to.equal(parseInt(myCount));
        });

或者……

var table = element.all(by.css(locator));
        table.all(by.tagName("tr")).count().then(function (data) {
            expect(data).to.equal(parseInt(mycount));
        });

列:

$(locator).all(by.xpath('.//tbody/tr/td')).count().then(function (data) {
            expect(data).to.equal(parseInt(myCount));
        });

或者……

var table = element.all(by.css(locator));
        table.all(by.tagName("td")).count().then(function (data) {
            expect(data).to.equal(parseInt(myCount));
        });

当我测试列数时,返回 25(或 26),我预计只有 6。 当我测试行数时,当我期望 4 时返回 0。 该表可以在这里找到 - http://toolsqa.com/automation-practice-table/

【问题讨论】:

    标签: javascript css css-selectors protractor


    【解决方案1】:

    这是一个简单的解决方案 //test.spec.js

     describe('all rows and columns', function() {
       var rows;
       var cols;
    beforeEach(function() {
      browser.waitForAngularEnabled(false);
      browser.get('http://www.toolsqa.com/automation-practice-table/');
    
      rows = element.all(by.xpath('.//tbody/tr'));
      cols=element.all(by.xpath('.//tbody/tr[1]/td'));
    }); 
    
    it('should list row and column counts', function() {
      //expect(rows.count()).toEqual(4);
      //expect(cols.count()).toEqual(6);
      rows.count().then(function(cnt) {
      console.log(cnt);
      })
      cols.count().then(function(cnt) {
      console.log(cnt);       
       })
      });
     });
    

    【讨论】:

      【解决方案2】:

      返回的计数是正确的,因为如果您在 chrome 中手动测试定位器,您将看到相同的结果。

      首先,您从定位器 .tsc_table_s13 中获取结果,然后在其上连接新的定位器。

      附加结果

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-02-01
        • 2020-09-04
        • 1970-01-01
        • 1970-01-01
        • 2018-01-19
        • 1970-01-01
        相关资源
        最近更新 更多