我是量角器的新手,并开始为我们现有的应用程序编写测试。
在过去的几天里,我花了很多时间试图在检查元素中的文本时解决间歇性的StaleElementReferenceError
问题。这是一个竞赛条件错误,由于我认为我已修复它,因此甚至更难以修复,但随后我会再次得到该错误。
我的代码如下:
await browser.wait(
ExpectedConditions.and(
ExpectedConditions.presenceOf(getMyElementArrayFinder().get(index)),
ExpectedConditions.visibilityOf(getMyElementArrayFinder().get(index)),
),
undefined,
`Waiting for visibility and prescence of element at index ${index} with expected text '${expectedText}'`,
);
console.log(`Getting text`);
const text = await getMyElementArrayFinder()
.get(index)
.getText();
console.log(`text: ${text}`);
expect(text).to.equal(
expectedTextArray[index],
`Expected text at index ${index} to be ${expectedTextArray[index]}`,
);
当我尝试解析元素的文本时得到StaleElementReferenceError: stale element reference: element is not attached to the page document
。
我无法理解如何等待元素可见和呈现(我可能只可以在此处检查可见性,但此刻我正在尝试使用皮带,牙套和胶带)...然后可以仍然会收到有关元素未附加到dom的警告。
我正在使用量角器5.4.0,selenium-server-standalone-jar 3.141.5和chromedriver 77.0.0
我已将SELENIUM_PROMISE_MANAGER
设置为false;