How to get a row and its column from a table with Protractor

北慕城南 提交于 2019-12-23 09:09: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

but I am unable to use code below to get each row and its column.

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

the following error message is displaying. Message: TypeError: Object [object Object] has no method 'findElements'


回答1:


Your grid setup is ok, but for the sake of a shortcut:

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

Regarding your question, avoid findElements and use chaining element or in this case all Protractor feature. But I'll use $$ shortcut again:

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


来源:https://stackoverflow.com/questions/26136496/how-to-get-a-row-and-its-column-from-a-table-with-protractor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!