angularjsprotractore2e-testingangularjs-e2egulp-protractor

Protractor E2E : get first value from getText() method?


I have element selector which is selected by repeater. I am getting

$186
Cost

from

element.getText().then(function (balance) {
          console.log(balance);
        });

I need to pick only $186, I tried to get by using first(); of the element. and balance[0]. But not finding a solution. Please suggest.


Solution

  • If the elements exist in the DOM like below:

    <span ng-repeat="record in records">$186</span><span ng-repeat="record in records">Cost</span>
    

    Then the following code works:

    element.all(by.repeater('record in records')).get(0).getText().then(function(txt) {
        console.log('txt:'+txt);
    });