getText 函数在 array.map() 中抛出过时的元素

我正在尝试使用 array.map 函数来查找存储在数组中的所有 webelement 的文本属性。有没有办法处理这个问题并重试查找文本属性?

使用正常 for 循环进行重试的标准解决方案是一种选择。想检查替代解决方案。

 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()));


莫回无
浏览 127回答 3
3回答

HUWWW

量角器each应该可以解决问题。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})

慕尼黑5688855

await关键字解决了一个承诺。element.all(by.xpath(planograms_Table_cart_Category))是不是一个承诺,hense不需要await它如上所述,这将起作用let name_planogram_table = await element.all(by.xpath(planograms_Table_cart_Category)).getText();console.log(name_planogram_table);// output// [//   "value1",//   "value2",//   "value3"// ]但!!!一年前有一个错误(也许它仍然存在),当你调用.getText()或.getAttribute()反对很多元素(30、50、100+)时,你会得到stale element错误。在这种情况下唯一的解决方案是for循环

神不在的星期二

您应该能够通过像这样在您的 elementFinderArray 上调用 getText() 来获取这些值let name_planogram_table = await element.all(by.xpath(planograms_Table_cart_Category)).getText();console.log(name_planogram_table);它将产生一个字符串数组。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript