欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

java selenium后报错Element not found in the cache元素定位要重新赋值之前的定义

发布时间:2025/4/16 编程问答 29 豆豆
生活随笔 收集整理的这篇文章主要介绍了 java selenium后报错Element not found in the cache元素定位要重新赋值之前的定义 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

习惯上把定位的元素在操作之前就定位好,

例如:

WebElement element1=driver.findElement(...);      ----------declaration1

WebElement element2=driver.findElement(...);      ----------declaration2

element1.click();                                 ---------------------action1

element2.click();                                 ---------------------action2

 

当遇到action1操作的时候,估计是js前端代码里面有一次刷新页面的动作,导致用操作action2的时候,会报错

org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up

没办法,只有重新赋值一遍element2了

第一次定位的元素,页面刷新后,在你第二次,第三次需要调用时,浏览器默认认为它是失效的,不允许你去调用它

 

转载于:https://www.cnblogs.com/limxiaosi/p/5970593.html

总结

以上是生活随笔为你收集整理的java selenium后报错Element not found in the cache元素定位要重新赋值之前的定义的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。