[英]getText function throws stale element inside array.map()
我正在尝试使用array.map函数来查找存储在数组中的所有webelements的文本属性。 有什么方法可以处理此问题,然后重试查找text属性?
带有标准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()));
量角器的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
})
您应该能够简单地通过在elementFinderArray上调用getText()来获得这些值,如下所示
let name_planogram_table = await element.all(by.xpath(planograms_Table_cart_Category)).getText();
console.log(name_planogram_table);
它将产生一个字符串数组。
await
关键字可解决承诺。 element.all(by.xpath(planograms_Table_cart_Category))
不是一个承诺,因此无需await
如上所述,这将起作用
let name_planogram_table = await element.all(by.xpath(planograms_Table_cart_Category)).getText();
console.log(name_planogram_table);
// output
// [
// "value1",
// "value2",
// "value3"
// ]
但!!! 一年前有一个错误(也许仍然存在),当您针对许多元素( .getAttribute()
调用.getText()
或.getAttribute()
,会出现stale element
错误。 在这种情况下,唯一的解决方案是for
循环
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.