習慣上把定位的元素在操做以前就定位好,前端
例如:瀏覽器
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
第一次定位的元素,頁面刷新後,在你第二次,第三次須要調用時,瀏覽器默認認爲它是失效的,不容許你去調用它