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了

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

 

posted @ 2016-10-17 17:35  xiaosi203  阅读(917)  评论(0编辑  收藏  举报