1

I'm trying to use array.map function to find the text properties of all the webelements stored in an array. Is there any way to handle this and retry finding the text property?

standard solution with normal for loop for retry is an option. Wanted to check for alternate solutions.

 let name_planogram_table = await element.all(by.xpath(planograms_Table_cart_Category));

 let uistringvaluearray = await Promise.all(name_planogram_table .map(name=> name.getText()));

3 Answers 3

2

Protractor's each should do the trick.

let uistringvaluearray = await name_planogram_table.each(async arrayElement => {
   return arrayElement.getText()
   //This is just a quick example
   //return the value, assign to another variable or do whatever you need to do
})
Sign up to request clarification or add additional context in comments.

3 Comments

wouldn't this throw stale element reference ? @Yuriy Gerasimovich
Even thou each is asynchronous it should not cause any issues. As Sergey Pleshakov mentioned there was a bug some time ago but personally for me it works with a list of 10+ elements at this moment (in my case I have a list of similar elements and my test needs to verify is there an element with desired text)
It will throw the same error, unless this was fixed in protractor stackoverflow.com/questions/53365309/…
1

You should be able to get these values simply by calling getText() on your elementFinderArray like so

let name_planogram_table = await element.all(by.xpath(planograms_Table_cart_Category)).getText();
console.log(name_planogram_table);

It will produce a array of strings.

Comments

1
  1. await keyword resolves a promise. element.all(by.xpath(planograms_Table_cart_Category)) is NOT a promise, hense no need to await it

  2. As mentioned above, this will work

let name_planogram_table = await element.all(by.xpath(planograms_Table_cart_Category)).getText();
console.log(name_planogram_table);

// output
// [
//   "value1",
//   "value2",
//   "value3"
// ]

BUT!!! There was a bug a year ago (maybe it still persist), when you call .getText() or .getAttribute() against A LOT of elements (30, 50, 100+) you get stale element error. The only solution in this case was for loop

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.