java selenium后报错Element not found in the cache元素定位要重新赋值之前的定义
習(xí)慣上把定位的元素在操作之前就定位好,
例如:
WebElement element1=driver.findElement(...);????? ----------declaration1
WebElement element2=driver.findElement(...);????? ----------declaration2
element1.click();???????????????????????????????? ---------------------action1
element2.click();???????????????????????????????? ---------------------action2
?
當(dāng)遇到action1操作的時候,估計是js前端代碼里面有一次刷新頁面的動作,導(dǎo)致用操作action2的時候,會報錯
org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
沒辦法,只有重新賦值一遍element2了
第一次定位的元素,頁面刷新后,在你第二次,第三次需要調(diào)用時,瀏覽器默認(rèn)認(rèn)為它是失效的,不允許你去調(diào)用它
?
轉(zhuǎn)載于:https://www.cnblogs.com/limxiaosi/p/5970593.html
總結(jié)
以上是生活随笔為你收集整理的java selenium后报错Element not found in the cache元素定位要重新赋值之前的定义的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Visual Studio插件
- 下一篇: post from open live