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

例如:

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了

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

 

相关文章:

  • 2021-04-29
  • 2022-12-23
  • 2022-03-01
  • 2022-12-23
  • 2022-01-09
  • 2022-12-23
  • 2021-11-09
  • 2021-06-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-21
  • 2022-12-23
  • 2022-12-23
  • 2021-08-30
  • 2022-01-24
相关资源
相似解决方案