Search code examples
angularjstestingprotractorend-to-end

Click on column in table - Protractor


I have pretty big compelx TABLE in HTML, and I need click first row:

<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.

As it looks like this I need to click on row number 20, 21,22 is here somebody who can help me with that?

I try with something like:

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

but i get error:

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

Please is here somebody who can help me with this?

EDIT: screen of code: enter image description here


Solution

  • Use element.all() with by.repeater():

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

    You may also need to scroll to the element before making a 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();
        });
    });
    

    See also: