Protractor 在量角器中遍历表

Protractor 在量角器中遍历表,protractor,Protractor,嗨,下面是我的html表格。我尝试使用量角器比较下表中的所有元素值 <table> <thead class="ui-table-thead"> <tr _ngcontent-c1="" class="ng-tns-c1-0 ng-star-inserted"> <th _ngcontent-c1="" class="ng-tns-c1-0" rowspan="2" style="text-

嗨,下面是我的html表格。我尝试使用量角器比较下表中的所有元素值

<table>
    <thead class="ui-table-thead">
            <tr _ngcontent-c1="" class="ng-tns-c1-0 ng-star-inserted">
                <th _ngcontent-c1="" class="ng-tns-c1-0" rowspan="2" style="text-align: center">User</th>
                <th _ngcontent-c1="" class="ng-tns-c1-0" colspan="5" style="text-align: center">Support</th>
            </tr>
            <tr _ngcontent-c1="" class="ng-tns-c1-0 ng-star-inserted">
                <th _ngcontent-c1="" class="ng-tns-c1-0" style="text-align: center">User1</th>
                <th _ngcontent-c1="" class="ng-tns-c1-0" style="text-align: center">User2</th>
                <th _ngcontent-c1="" class="ng-tns-c1-0" style="text-align: center">User3</th>
                <th _ngcontent-c1="" class="ng-tns-c1-0" style="text-align: center">User4</th>
                <th _ngcontent-c1="" class="ng-tns-c1-0" style="text-align: center">User4</th>
                </tr>
        </thead>
        <tbody class="ui-table-tbody">
            <tr _ngcontent-c1="" class="ng-tns-c1-0 ng-star-inserted">
                <td _ngcontent-c1="" class="ng-tns-c1-0">value1</td>
                <td _ngcontent-c1="" class="ng-tns-c1-0">value2</td>
                <td _ngcontent-c1="" class="ng-tns-c1-0">value3</td>
            </tr>
            <tr _ngcontent-c1="" class="ng-tns-c1-0 ng-star-inserted">
                <td _ngcontent-c1="" class="ng-tns-c1-0">value11</td>
                <td _ngcontent-c1="" class="ng-tns-c1-0">value12</td>
                <td _ngcontent-c1="" class="ng-tns-c1-0">value13</td>
            </tr>
            <tr _ngcontent-c1="" class="ng-tns-c1-0 ng-star-inserted">
                <td _ngcontent-c1="" class="ng-tns-c1-0">value21</td>
                <td _ngcontent-c1="" class="ng-tns-c1-0">value22</td>
                <td _ngcontent-c1="" class="ng-tns-c1-0">value23</td>
            </tr>
        </tbody>
    </table>

使用者
支持
用户1
用户2
用户3
用户4
用户4
价值1
价值2
价值3
价值11
价值12
价值13
价值21
价值22
价值23
无法获得正确的解决方案。如有任何帮助,将不胜感激。谢谢

试试这个:

    function AddBetternameforfuntionhere(){
    var headerRows = element.all(by.css(".ui-table-thead")).first().all(by.tagName('tr'));
    var headerIndex = headerRows.all(by.tagName('th'));
    var counter = 0;

    headerIndex.getText().then(function(conforms){
        conforms.forEach(function(value){
           //perform the validation here
        })
    })
    }
forEach将迭代,直到数组的结尾进入.getText()为止

对于正文,代码类似,例如,如果您想验证特定列,可以使用此代码获取值:

        var expectedCells = element.all(by.css('#'+/*TableId*/+' tr td:nth-of-type('+columnNumber+')'));
    expectedCells.each((eachCell) => {
        eachCell.getText().then((cellText) => {
            expect(cellText).toBe(arrayOfvalues);
        });
    });

只比较tbody中的值或表头中的值。当您说“比较值”时是什么意思?first()表示第一个tr标记正确。?还有,是否可以获得头的数量计数?first用于告诉量角器,如果有更多的项具有相同的类(或您使用的任何其他选择器),则您希望获取其中的第一个项,以便在使用时获取第二个和子项。例如,get(2)而不是.first()