问题标签 [staleelementreferenceexception]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
298 浏览

vb.net - Selenium VB:OpenQA.Selenium.StaleElementReferenceException:过时的元素引用:元素未附加到页面文档

我正在尝试使用 LinkText 单击一个元素。例如:

但是,我收到以下错误

即使元素在网页上可见,为什么它无法使用LinkText找到元素是否有原因?有没有办法解决这个问题,请帮忙?

0 投票
4 回答
7559 浏览

python - 消息:过时的元素引用:元素未附加到页面文档

我试图自动化我们几乎每天都做的一项任务。我读到 python 结合 selenium 将是完成这项任务的完美选择。欢迎任何建议:)

请参阅下面的代码。

但它返回这个

0 投票
1 回答
111 浏览

java - 迭代嵌入式链接时出现 StaleElementReferenceException

在我的网页上,我有一个部分链接列表,每个部分都有详细信息的链接。我正在尝试转到每个部分,然后验证所有链接都没有损坏。

StaleElementReferenceException问题是在检查了第一部分的详细信息后,我得到了一个。我猜这是因为在迭代细节并返回 Selenium 后不会将其余部分列表视为当前?

我可能会为部分创建一个所有 href 的列表,然后遍历该列表导航到特定部分链接,然后检查详细信息的链接。但也许还有其他/更简单的解决方案?

0 投票
1 回答
959 浏览

python - Selenium Python:循环中间 - 陈旧元素错误

所以我的代码试图通过一个链接列表(所有链接的可见文本都是“年度”),然后,当在新网页上时,在年份的下拉列表中迭代大约 20 年并下载一个数据集每年。所以有两个循环。我的代码陷入了年循环 - 也就是说,对于相同的“年度”,它在 2 年后出现过时元素错误。

我正在使用 chrome,这是我的代码的相关部分:

错误如下:selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attach to the page document

将不胜感激任何帮助!我试图通过答案,但由于我正在使用 2 个循环,其中一个工作正常,因为它可以工作长达 2 年,所以我无法弄清楚。

更新:完整的错误信息:

0 投票
2 回答
1341 浏览

python - For 循环中的 Python/Selenium 陈旧元素参考

我在遍历公司 ID 列表并在搜索栏中使用它们时遇到问题。当文本文件仅包含一个 ID 时,我的代码工作得很好,但是当我将第二个 ID 添加到列表中时,它甚至不会对第一个 ID 执行最后一次单击,更不用说搜索第二个 ID,然后给我过时的元素引用异常。这让我发疯,所以任何帮助都会令人惊叹。如果我不理解有关更多信息或您的解决方案的请求,请耐心等待。

代码:

追溯:

0 投票
0 回答
91 浏览

python-3.x - 浏览for循环时出现过时异常错误

在上面的代码中,我在它运行一次的最后一个 for 循环中得到了陈旧的异常错误,但是对于下拉列表中的下一个值,我得到了异常。我正在尝试完成任务,因为第一个下拉列表描述了国家,第二个描述了他所在国家/地区的州,第三个描述了该州的城市。我需要遍历每个国家/地区每个州的所有城市,但给我一个陈旧的异常错误

如下:

0 投票
4 回答
29467 浏览

java - 如何使用 Selenium 从动态下拉列表中选择一个选项?

我正在尝试单击下拉值以从 Make my trip http://www.makemytrip.com/中的字段中选择城市。但是得到过时的元素引用异常。ID 在页面加载时会发生变化。试过下面的代码:

0 投票
1 回答
542 浏览

python - 过时的元素参考:元素未使用 chrome Web 驱动程序附加到页面文档

我已经在下午阅读了很多处理这个问题的线程,但不幸的是我目前缺少解决方案:(

我尝试抓取这个网站:https ://www.kumon.co.uk/find-a-tutor/

我使用此代码来存储不同商店的每个 url。为此,我必须迭代下一页直到最后一页。

这是我使用的代码:

不幸的是我得到了一个

selenium.common.exceptions.StaleElementReferenceException:消息:过时的元素引用:元素未附加到页面文档

要使用 Try... 除了不是一个好的解决方案,我正在寻找一个强大的解决方案。我应该从 Chrome 切换到 Firefox 吗?

提前谢谢,尼古拉斯。

0 投票
1 回答
750 浏览

java - Selenium Java - Stale element exception on iterating using enhanced for loop

Use case:

Click button on page It open a new div popup (which has all this parent -> child - subchild heirarchy inorder to select template - There can be n number of child and subchilds) Iterate to select each subchild - but have other steps to follow post selecting each child For e.g. Have to click add on div popup , enter name for page on small popup that shows up after it, click Add and then navigate to the earlier page (with herirachy) again to select the next sub child Now, it gives Stale element reference exception

Inorder to avoid stale element exception, tried with while loop (along with try and catch) to attempt atleast twice for the child selection step and now it executes but in each loop it always selects first child - Note, it doesnt enter the try catch loop again.

Code for reference

} }

0 投票
2 回答
590 浏览

java - Selenium:如何判断 RemoteWebDriver.findElements(By) 是否可以抛出 StaleElementReferenceException?

据我了解,只有在代码对实例进行操作时才会引发此类异常WebElement,并在重新加载或删除相应的 DOM 元素后对其调用方法。

因此,为了确定是否可以抛出该异常,我在接口实现RemoteWebDriver.findElements(By)的源代码中寻找了那种代码(in )。但是,深入到's 代码中的调用堆栈最终对我来说变得太难了。RemoteWebDriverWebDriverselenium-remote-driver-3.8.1.jarRemoteWebDriver

所以我的问题是:除了试图通过检查 Selenium 源来弄清楚这一点之外,还有没有更好的方法来判断一个WebDriver方法是否findElements(By)能够抛出StaleElementReferenceException?它是一个RuntimeException,而 Selenium JavaDoc 没有@throws它。