解决webdriver(Element not found in the cache - perhaps the page has changed since it was looked up )
2013-08-05 23:01
686 查看
测试技术交流群:161204772
悦分享测试联盟:136924235
悦分享主页:http://www.bjhxcc.com/special/2013/0822/yfx.htm
解释:这种问题是由于,当我们执行某个ajax操作后,对于之前定位到的DOM对象与之发生变化,所以导致查找不到
解决思路:让driver查找DOM元素时不进行缓存查找,而是对当前页面进行查询
使用pageFactory类结合FindBy注释完成此操作
1、定义一个类,封装WebElement对象元素
class MyElement{
@FindBy(xpath="//input[@id='hello']")
public WebElement userName;
public WebElement password; //如果该元素存在id或name属性,直接使用id或name作为属性名,不必在使用@FindBy注解
public MyElement(WebDriver driver){
PageFactory.initElements(driver,this);
}
}
public class Test{
WebDriver driver = new FirefoxDriver();
MyElement my = new MyElement(driver);
my.userName.sendKeys("ray");
my.password.sendKeys("123456");
}
部分元素如果需要从cache中读取,只需在MyElement类中的属性加上@CacheLookUp注解即可,当然如果没有被@FindBy注解的属性,不必这样操作,默认会Cache查找
悦分享测试联盟:136924235
悦分享主页:http://www.bjhxcc.com/special/2013/0822/yfx.htm
解释:这种问题是由于,当我们执行某个ajax操作后,对于之前定位到的DOM对象与之发生变化,所以导致查找不到
解决思路:让driver查找DOM元素时不进行缓存查找,而是对当前页面进行查询
使用pageFactory类结合FindBy注释完成此操作
1、定义一个类,封装WebElement对象元素
class MyElement{
@FindBy(xpath="//input[@id='hello']")
public WebElement userName;
public WebElement password; //如果该元素存在id或name属性,直接使用id或name作为属性名,不必在使用@FindBy注解
public MyElement(WebDriver driver){
PageFactory.initElements(driver,this);
}
}
public class Test{
WebDriver driver = new FirefoxDriver();
MyElement my = new MyElement(driver);
my.userName.sendKeys("ray");
my.password.sendKeys("123456");
}
部分元素如果需要从cache中读取,只需在MyElement类中的属性加上@CacheLookUp注解即可,当然如果没有被@FindBy注解的属性,不必这样操作,默认会Cache查找
相关文章推荐
- Webdriver如何解决页面元素过期:org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
- selenium Element not found in the cache - perhaps the page has changed since it was looked up接解决
- selenium+python自动化88-批量操作循环点击报错:Element not found in the cache - perhaps the page has changed since it was looked up
- Selenium Webdriver : Element not found in the cache - perhaps the page has changed since it
- 解决 Previous operation has not finihsed; run ‘cleanup’ if it was interrupted Please execute the ‘Cleanup’ command
- Note: This element has no attached source and Javadoc could not be found in the attached Javadoc解决办法
- 解决:The Apache Tomcat Native library which allows optimal performance in production environments was not found
- 解决tomcat开始出现in production environments was not found on the java.library.path:xxx
- “Location of the Android SDK has not been set up in the preferences”问题的解决
- 对于 Package gstreamer-0.10.23 was not found in the pkg-config search path. 的问题的解决
- Python Version 2.7 required which was not found in the registry 问题解决
- svn报错cleanup failed–previous operation has not finished; run cleanup if it was interrupted的解决办法
- 安装scipy或者numpy时弹出python2.7 was not found in the registry 的解决办法
- selenium之 坑:页面刷新(StaleElementReferenceException: Message: Element not found in the cache...)
- 解决“The Apache Portable Runtime which allows optimal performance in production environments was not found on the java.library.pat
- 安装win32com报错-Python Version 2.7 required which was not found in the registry 问题解决 .
- 解决:The Apache Tomcat Native library which allows optimal performance in production environments was not found
- eclipse打包apk时提示the zipalign tool was not found in the sdk解决方法
- Python Version 2.7 required which was not found in the registry 问题解决
- Python version 3.4 required, which was not found in the registry.解决