为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

莫回无 2021-10-21 13:28:28
我正在尝试使用 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()));
查看完整描述

3 回答

?
HUWWW

TA贡献1874条经验 获得超12个赞

量角器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

})


查看完整回答
反对 回复 2021-10-21
?
慕尼黑5688855

TA贡献1848条经验 获得超2个赞

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循环


查看完整回答
反对 回复 2021-10-21
?
神不在的星期二

TA贡献1963条经验 获得超6个赞

您应该能够通过像这样在您的 elementFinderArray 上调用 getText() 来获取这些值


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

console.log(name_planogram_table);

它将产生一个字符串数组。


查看完整回答
反对 回复 2021-10-21
  • 3 回答
  • 0 关注
  • 126 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信