【问题标题】:How to get a row and its column from a table with Protractor如何使用量角器从表中获取行及其列
【发布时间】:2017-06-14 07:22:21
【问题描述】:
<div class="k-grid-content">
    <table>
        <tbody>
            <tr>
                <td>row1Col1</td>
                <td>row1Col2</td>
                <td>row1Col3</td>
            </tr>

            <tr>
                <td>row2Col1</td>
                <td>row3Col2</td>
                <td>row4Col3</td>
            </tr>

            <tr>
                <td>row3Col1</td>
                <td>row3Col2</td>
                <td>row3Col3</td>
            </tr>

        </tbody>
    </table>
</div>


var grid = element.all(by.css('.k-grid-content tr')); //this will return row1,row2,row3

但我无法使用下面的代码来获取每一行及其列。

grid.each.each(function(row){
    var rowElems = row.findElements(by.tagName('td'));
    expect(rowElems.get(0).getText()).toMatch('/Col1/');
});

正在显示以下错误消息。 信息: TypeError: Object [object Object] 没有方法'findElements'

【问题讨论】:

    标签: protractor


    【解决方案1】:

    您的grid 设置没问题,但为了走捷径:

    var grid = $$('.k-grid-content tr');
    

    关于您的问题,请避免使用 findElements 并使用链接 element 或在这种情况下使用 all Protractor 功能。但我会再次使用$$ 快捷方式:

    grid.each(function(row) {
      var rowElems = row.$$('td');
      expect(rowElems.count()).toBe(3);
      expect(rowElems.get(0).getText()).toMatch('/Col1$/');
    });
    

    【讨论】:

    • 不客气,别忘了把答案标记为正确;)
    • @LeoGalluci:这有点奇怪,对我来说“.each”不起作用,而不是像 grid.filter(function(row) 中的“.filter”那样工作{对这种奇怪的行为有什么想法吗?
    • idk @igniteram1 请注意我的答案是 2014 年的,所以它现在可以工作了
    猜你喜欢
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 2015-10-20
    • 2011-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多