Getting text from array of elements protractor

krzygol

this is my first post so please go easy one me. :)

I'am new to protractor therefore I would like to ask for your help. I've been asked to write a test for the folowing code:

<div class="content ps-container ps-active-y expand" ng-class={hide:items.length === 2}" ng-transclude="" csf-product-navigator-content="" csf-scrollbar="" style="">
 <div class="product-wrp prod-active" ng-class="{'prod-active' : active, 'odd' : (odd === true && !active), 'even' : (odd !== true && !active)}" ng-repeat="product in accounts" csf-product-navigator-item="">
  <div class="product-wrp odd" ng-class="{'prod-active' : active, 'odd' : (odd === true && !active), 'even' : (odd !== true && !active)}" ng-repeat="product in accounts" csf-product-navigator-item="">
   <div class="product-item animate-hide" ng-click="onDropdowmItemClick()" ng-transclude="" csf-product-navigator-anim-item="">
    <div class="ng-scope" ng-repeat="product in accounts" csf-product-navigator-item="">
     <div class="navigator-view ng-hide" ng-show="active">
      <div class="" ng-hide="active">
       <div class="product-choice ng-scope" ng-if="product.type !== 'SM'">
        <section class="product-name">
         <header class="ng-scope" ng-if="product.name">
          <p class="product-details" ng-show="product.type">
           <span class="ng-binding" ng-bind="product.no">PL84 9101 0003 2001 0006 1883 0004</span>
          </p>
        </section>
        <section class="product-amount">
       </div>
      </div>
     </div>
    </div>
   </div>
  <div class="product-wrp even" ng-class="{'prod-active' : active, 'odd' : (odd === true && !active), 'even' : (odd !== true && !active)}" ng-repeat="product in accounts" csf-product-navigator-item="">
  <div class="product-wrp even" ng-class="{'prod-active' : active, 'odd' : (odd === true && !active), 'even' : (odd !== true && !active)}" ng-repeat="product in accounts" csf-product-navigator-item="">
  <div class="product-wrp odd" ng-class="{'prod-active' : active, 'odd' : (odd === true && !active), 'even' : (odd !== true && !active)}" ng-repeat="product in accounts" csf-product-navigator-item="">
  <div class="product-wrp even" ng-class="{'prod-active' : active, 'odd' : (odd === true && !active), 'even' : (odd !== true && !active)}" ng-repeat="product in accounts" csf-product-navigator-item="">

Goal is to get the number of the products on the dropdown list.

So I figured i should get all elements in the container and then use function to go through them.

This is my code:

features(iOwe):

var iOwe = function () {
  this.accNo = element(by.className('content ps-container ps-active-y expand')).all(by.className('product-item animate-hide'))
}

Spec(iOwe):

it('should display accounts numbers on dropdown list', function () {
  expect(iOwe.accNo.count()).not.toBe(0);
  iOwe.accNo.each(function(elem) {
    elem.element(by.className('product-details')).getText()
    .then
    (function (text){
        console.log(text);
    });
  });

The problem is that each time I run tests I get diffrent output in console. Getting only first 3/4 strings (should be 7) and rest is empty.

Thanks for help

EDIT: I checked what exactly happens during test by adding browser.sleep(5000); each time console prints string and suprisingly I found out that I have to actually see (in browser) the following account to allow test to read it.

krzygol

I got an anwser to my question,it was not a matter of selectors/matchers.

As I found out according to this Article in order to .getText() u have to actually see the element in browser otherwise it will return empty string.

I decided to find another way to get the text and I used

.getAttribute()

to get the string.

Basically i changed :

elem.element(by.css('span.ng-binding')).getText()

to

elem.element(by.css('span.ng-binding')).getAttribute('outerHTML')

And it returned string with accnumber.

But... This is not what I wanted. I wanted to check if the element is actually visible in browser and folowing solution wont work.

Then i found this Question,it shows how to scroll down to element in your browser You want to check.

So i edited my code:

it('should display accounts numbers on dropdown list', function () {
  expect(iOwe.accNo.count()).not.toBe(0);
  iOwe.accNo.each(function(elem) {
    browser.executeScript('arguments[0].scrollIntoView()', elem.getWebElement()) //Scroll down to element
    .then
    elem.element(by.className('product-details')).getText()
    .then
    (function (text){
      console.log(text);
    });
});

And this is an anwser to my question.

Thanks for help!

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Getting Text from Repeater in Protractor

From Dev

Getting Text from Modal : Protractor / Webdriver

From Dev

getting data from an array test using protractor

From Dev

Getting elements from a unicode text

From Dev

Getting elements from array by class

From Dev

Multiply values from text of elements on runtime-protractor

From Dev

Protractor clicking through an array of elements

From Dev

Getting UI elements by type from Control array?

From Dev

Getting a final value from elements.all.each in the protractor library 4.0.1

From Dev

Getting array values from separate text file

From Dev

Pick elements of an array from text file

From Dev

Adding tooltip to SVG elements with text from an array

From Dev

Protractor - Counting the no.of elements and Display all the elements with For loop is Not getting executed

From Dev

Create array from map in Protractor

From Dev

Getting the text from all p elements in a div with BeautifulSoup

From Dev

Getting elements in an array?

From Dev

Getting elements from xml and storing it in array using shell script

From Dev

Getting elements from array based on property values (AngularJS)

From Dev

Getting a stack of 5 elements from an array based on a single index

From Dev

Getting elements from an HList

From Dev

protractor how to get text from div?

From Dev

Getting text values of div elements

From Dev

Getting data from text box and converting to byte array in specified format

From Dev

Getting text from a URL and transforming before entry in array - Python

From Dev

C++ - Getting values from text file into array for comparison

From Dev

Matching input from a text field against elements of an array

From Dev

Matching input from a text field against elements of an array

From Dev

protractor return array of values from repeater

From Dev

How to get One value from an array (protractor)?

Related Related

  1. 1

    Getting Text from Repeater in Protractor

  2. 2

    Getting Text from Modal : Protractor / Webdriver

  3. 3

    getting data from an array test using protractor

  4. 4

    Getting elements from a unicode text

  5. 5

    Getting elements from array by class

  6. 6

    Multiply values from text of elements on runtime-protractor

  7. 7

    Protractor clicking through an array of elements

  8. 8

    Getting UI elements by type from Control array?

  9. 9

    Getting a final value from elements.all.each in the protractor library 4.0.1

  10. 10

    Getting array values from separate text file

  11. 11

    Pick elements of an array from text file

  12. 12

    Adding tooltip to SVG elements with text from an array

  13. 13

    Protractor - Counting the no.of elements and Display all the elements with For loop is Not getting executed

  14. 14

    Create array from map in Protractor

  15. 15

    Getting the text from all p elements in a div with BeautifulSoup

  16. 16

    Getting elements in an array?

  17. 17

    Getting elements from xml and storing it in array using shell script

  18. 18

    Getting elements from array based on property values (AngularJS)

  19. 19

    Getting a stack of 5 elements from an array based on a single index

  20. 20

    Getting elements from an HList

  21. 21

    protractor how to get text from div?

  22. 22

    Getting text values of div elements

  23. 23

    Getting data from text box and converting to byte array in specified format

  24. 24

    Getting text from a URL and transforming before entry in array - Python

  25. 25

    C++ - Getting values from text file into array for comparison

  26. 26

    Matching input from a text field against elements of an array

  27. 27

    Matching input from a text field against elements of an array

  28. 28

    protractor return array of values from repeater

  29. 29

    How to get One value from an array (protractor)?

HotTag

Archive