【问题标题】:Click on column in table - Protractor单击表中的列 - 量角器
【发布时间】:2015-03-02 23:06:04
【问题描述】:

我在 HTML 中有相当大的 compelx TABLE,我需要点击第一行:

<div class="ui-grid-canvas"> //this is whole table
 <div ng-repeat="(rowRenderIndex, row) in rowContainer.renderedRows track by $index" class="ui-grid-row ng-scope" ng-style="containerCtrl.rowStyle(rowRenderIndex)" ng-class="{'ui-grid-row-selected': row.isSelected}" style="margin-top: 0px;"> //this is one line
   <div ui-grid-row="row" row-render-index="rowRenderIndex" class="ng-isolate-scope"> //this is blanked part (740x0px)
    <div ng-repeat="(colRenderIndex, col) in colContainer.renderedColumns track by col.colDef.name" class="ui-grid-cell ng-scope ui-grid-col0 ui-grid-row-header-cell" ng-class="{ 'ui-grid-row-header-cell': col.isRowHeader }" ui-grid-cell="">
     <div class="ui-grid-disable-selection ng-scope"> //stil first column
      <div class="ui-grid-cell-contents"> //stil first column
       <div class="ui-grid-selection-row-header-buttons ui-grid-icon-ok ng-scope" ng-class="{'ui-grid-row-selected': row.isSelected}" ng-click="selectButtonClick(row, $event)">&nbsp;</div> //clickable part of first element.

看起来像这样我需要点击第 20 行,21,22 有人可以帮助我吗?

我尝试使用类似的东西:

element(by.css('.ui-grid-canvas').row(22)).element(by.css('[ng-click="selectButtonClick(row, $event)"]')).click();

但我得到错误:

r(".ui-grid-canvas") has no method 'row'

请问有人可以帮我解决这个问题吗?

编辑: 代码屏幕:

【问题讨论】:

    标签: angularjs testing protractor end-to-end


    【解决方案1】:

    element.all()by.repeater() 一起使用:

    element.all(by.repeater('(rowRenderIndex, row) in rowContainer.renderedRows')).then(function(arr) {
      arr[20].all(by.css('[ng-click^=selectButtonClick]')).first().click();
    });
    

    您可能还需要在点击之前滚动到元素

    var scrollIntoView = function () {
        arguments[0].scrollIntoView();
    }
    
    element.all(by.repeater('(rowRenderIndex, row) in rowContainer.renderedRows')).then(function(arr) {
        var row = arr[20];
        browser.executeScript(scrollIntoView, row.getWebElement()).then(function () {
            row.all(by.css('[ng-click^=selectButtonClick]')).first().click();
        });
    });
    

    另见:

    【讨论】:

    • 嘿,alecxe,我非常感谢您尝试提供帮助 :) 很难为量角器找到任何东西。无论如何,我尝试听从您的建议,它会向我抛出错误:NoSuchElementError: No element found using locator: By.cssSelector("[ng-click=\"selectButtonClick(row, $event)\"]")
    • @Andurit 好的,但你确定每个重复部分都有这个可点击的divng-clickselectButtonClick(row, $event)
    • 这看起来真的很蹩脚,但我不知道如何测试它。
    • 亲爱的 alecxe 感谢您的快速响应,看到有人如此关心我的问题真是太酷了。您的最后一个代码抛出此错误: TypeError: Object function (subLocator) { return this.all(subLocator).toElementFinder_(); } 没有方法'all'
    • 错误:索引超出范围。尝试访问索引处的元素:0,但只有 0 个元素与定位器匹配 By.cssSelector("[ng-c lick^=selectButtonClick]")
    猜你喜欢
    • 1970-01-01
    • 2019-06-21
    • 2017-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多