我有一个带有多个TR行的表,我需要能够单击<tr>或VALUE为91的任何child <td>,在下面的示例中只有2个值,但将来可能有20个它们,它们的排序方式也可以不同。

有什么方法可以从下面查找此值,然后单击该元素?

<td class="ultranarrow ng-binding">91</td>


表格HTML:

                       <tbody>
                        <!-- end ngRepeat: row in gridData | filter:gridFilter --><tr ng-click="toggle(row)" ng-repeat="row in gridData | filter:gridFilter" ng-class="{
                                selected: row.selected,
                                selectable: row.selectable,
                                'text-danger': !row.selectable,
                                modified: row.modified
                            }" class="ng-scope selectable">
                            <td class="minimal text-center">
                                <!-- ngIf: row.selectable --><a class="glyphicon glyphicon-ok dehover ng-scope text-disabled" ng-class="'text-' + (row.selected ? 'primary' : 'disabled')" ng-if="row.selectable"></a><!-- end ngIf: row.selectable -->
                            </td>
                            <td class="ultranarrow ng-binding">91</td>
                            <td class="ng-binding">Spoluúčast (dokumentace)</td>
                            <td class="narrow">
                                <!-- ngIf: row.selected -->
                            </td>
                            <td class="ultranarrow ng-binding">KČ</td>
                        </tr><!-- end ngRepeat: row in gridData | filter:gridFilter --><tr ng-click="toggle(row)" ng-repeat="row in gridData | filter:gridFilter" ng-class="{
                                selected: row.selected,
                                selectable: row.selectable,
                                'text-danger': !row.selectable,
                                modified: row.modified
                            }" class="ng-scope selectable">
                            <td class="minimal text-center">
                                <!-- ngIf: row.selectable --><a class="glyphicon glyphicon-ok dehover ng-scope text-disabled" ng-class="'text-' + (row.selected ? 'primary' : 'disabled')" ng-if="row.selectable"></a><!-- end ngIf: row.selectable -->
                            </td>
                            <td class="ultranarrow ng-binding">95</td>
                            <td class="ng-binding">Předcházející poškození (výpočet)</td>
                            <td class="narrow">
                                <!-- ngIf: row.selected -->
                            </td>
                            <td class="ultranarrow ng-binding">KČ</td>
                        </tr><!-- end ngRepeat: row in gridData | filter:gridFilter -->
                    </tbody>

最佳答案

当需要精确值匹配时,xpath是您的朋友。这应该可以解决问题:

element.all(by.xpath('.//td[.="91" and @class="ultranarrow ng-binding"]')).click();

关于javascript - 从表中获取属性- Protractor ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30869353/

10-10 05:42