gpt4 book ai didi

javascript - 使用 each() 方法时 Protractor 陈旧元素引用

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:29:35 25 4
gpt4 key购买 nike

由于在 Protractor 中使用 each() 方法,我收到以下错误。它过去运行良好,但现在一直因此错误而失败。

Failed: stale element reference: element is not attached to the page document

element.all(bars).each((element) => element.getCssValue('width'))

是否有其他选择或原因?

(为清楚起见,我只想获取一组称为栏的网络元素中每个元素的宽度。)

谢谢!

最佳答案

简而言之,这是因为 each()只是同时对所有元素发出命令。在您的情况下,您可能需要这样做 element.all(bars).getCssValue('width')).then(array => {/*do what you want with returned array here*/})

* 已编辑 *

你想做的是

element.all(bars).getCssValue('width')).then(array => {
// tests is at least one element will not be "0px"
let elementHasWidth = array.some(elem => elem !== "0px");
expect(elementHasWidth).toBe(true);
})

关于javascript - 使用 each() 方法时 Protractor 陈旧元素引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53365309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com