“未在缓存中找到元素”在Selenium WebDriver中 [英] "Element not found in the cache" in Selenium WebDriver

查看:207
本文介绍了“未在缓存中找到元素”在Selenium WebDriver中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法使用Selenium WebDriver清除浏览器缓存?如果我可以为更大的测试用例清除缓存会有所帮助,有时我得到以下异常:

Is there any way to clear browser cache using Selenium WebDriver? It would help if I can clear cache for larger test cases, sometimes I get the following exception :

缓存中找不到元素 - 可能页面已更改,因为它被查了起来。

"Element not found in the cache - perhaps the page has changed since it was looked up".

我正在使用java。任何建议都将不胜感激,谢谢!

I'm using java. Any suggestions would be appreciated, thanks!

推荐答案

该问题与浏览器缓存无关。这意味着您对Browser DOM中的对象有陈旧的引用。通常可以有以下原因:

The problem has nothing to do with browser cache. It means that you have a stale reference to an object in the Browser DOM. Typically there can be following reasons:


  1. 您在一个页面上找到一个元素。然后在浏览器中导航到另一个页面。然后在Java代码中尝试使用第1页中的元素。它不再有效,你将得到一个StaleElementReferenceException,消息在缓存中找不到元素......

  1. You find an element on one page. Then navigate in browser to another page. Then in Java code you attempt to use the element from the 1st page. It is not valid any more, and you will get a StaleElementReferenceException with the message "Element not found in the cache ..."

你找到一个元素一页。然后使用JavaScript修改页面,您的元素将从DOM中删除。即使创建了具有相同ID和样式的新元素,它也是一个新实例,并且JavaCode中的引用是陈旧的。您需要再次查找此元素,您将获得正确的参考。

You find an element on one page. Then the page is being modified with JavaScript, your element is removed from DOM. Even if a new element with the same ID and styles is created, it is a new instance, and reference in your JavaCode is stale. You need to look up this element again, and you will get the correct reference.

这篇关于“未在缓存中找到元素”在Selenium WebDriver中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆