习惯上把定位的元素在操做以前就定位好,前端
例如:浏览器
WebElement element1=driver.findElement(...); ----------declaration1element
WebElement element2=driver.findElement(...); ----------declaration2selenium
element1.click(); ---------------------action1it
element2.click(); ---------------------action2io
当遇到action1操做的时候,估计是js前端代码里面有一次刷新页面的动做,致使用操做action2的时候,会报错cli
org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up习惯
没办法,只有从新赋值一遍element2了ps
第一次定位的元素,页面刷新后,在你第二次,第三次须要调用时,浏览器默认认为它是失效的,不容许你去调用它