- gkpandiActive particpant
- Posts : 14
Join date : 2013-05-23
Can anyone help me to resolve the cache error in selenium webdriver?
Thu May 30, 2013 7:27 pm
Hi Friends,
I have written a java code for adding 'vendor' information thru our web application (i.e URL).
The script will perform the following:
1. Open up Application - Java Method Name : OpenApplication();
2. Read Data from Excel spreadsheet - Java Method Name : GetDataFromExcel()
3. Add Vendor - Java Method Name : SaveSystemVendorMethod()
In Excel spreadsheet, there are TWO rows available. Script is running successfully till the TWO rows fetched from the excel and added successfully. After that, it is displaying the following error message.
" Element not found in the cache - perhaps the page has changed since it was looked up "
I tried with implicit wait method like this.
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
But, it is not working. See my complete source code.
DTO Class:
public class SystemVendorDTO {
private String SystemCode;
private String SystemOID;
private String SystemName;
private String NameSpace;
private String Description;
public SystemVendorDTO() {
}
public SystemVendorDTO(String systemCode, String systemOID,
String systemName, String nameSpace, String description) {
SystemCode = systemCode;
SystemOID = systemOID;
SystemName = systemName;
NameSpace = nameSpace;
Description = description;
}
public void setSystemCode(String systemCode) {
this.SystemCode = systemCode;
}
public String getSystemCode() {
return SystemCode;
}
public void setSystemOID(String systemOID) {
this.SystemOID = systemOID;
}
public String getSystemOID() {
return SystemOID;
}
public void setSystemName(String systemName) {
this.SystemName = systemName;
}
public String getSystemName() {
return SystemName;
}
public void setNameSpace(String nameSpace) {
this.NameSpace = nameSpace;
}
public String getNameSpace() {
return NameSpace;
}
public void setDescription(String description) {
this.Description = description;
}
public String getDescription() {
return Description;
}
}
Main Class:
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import jxl.Sheet;
import jxl.Workbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Function;
public class AddSystemVendor {
private WebDriver driver;
private ArrayList vendors = new ArrayList();
SystemVendorDTO systemVendorDTO;
@BeforeClass
public void StartUp() throws Exception {
driver = new FirefoxDriver();
http://this.GetDataFromExcel();
}
@Test(testName = "Open Application")
public void OpenApplication() {
driver.get("http://10.0.25.122:8090/hie");
WebElement mnuElement = driver.findElement(By
.xpath("//div[@id='j_idt10:j_idt11']/ul/li[7]/a/span[2]"));
WebElement submnuElement = driver.findElement(By
.xpath("//a[@id='j_idt10:j_idt36']/span[2]"));
try {
Actions builder = new Actions(driver);
// Move cursor to the Main Menu Element
builder.moveToElement(mnuElement).build().perform();
submnuElement.click();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.navigate().refresh();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
// Reset input fields
public void ClearInputFields(ArrayList elements) {
WebDriverWait wait = new WebDriverWait(driver, 10);
for (int i = 0; i < 5; i++) {
wait.until(presenceOfElementLocated(By.id(elements.get(i))));
driver.findElement(By.id(elements.get(i))).clear();
}
}
@Test(description = "Add System Vendor")
public void SaveSystemVendorMethod() throws Exception {
for (SystemVendorDTO vendor : vendors) {
ArrayList elements = new ArrayList();
// Fill all the mandatory fields and click submit button
driver.findElement(By.id("j_idt51:systemCode")).sendKeys(
vendor.getSystemCode());
driver.findElement(By.id("j_idt51:systemOID")).sendKeys(
vendor.getSystemOID());
driver.findElement(By.id("j_idt51:SystemName")).sendKeys(
vendor.getSystemName());
driver.findElement(By.id("j_idt51:nameSpace")).sendKeys(
vendor.getNameSpace());
driver.findElement(By.id("j_idt51:description")).sendKeys(
vendor.getDescription());
// Click on Add System Vendor Button click
driver.findElement(By.name("createVendor")).click();
System.out.println(vendor.getSystemCode());
System.out.println("System Vendor Added Successfully");
// Add elements id into ArrayList
elements.add("j_idt51:systemCode");
elements.add("j_idt51:systemOID");
elements.add("j_idt51:SystemName");
elements.add("j_idt51:nameSpace");
elements.add("j_idt51:description");
// Reset the input fields
ClearInputFields(elements);
}
}
private static Function presenceOfElementLocated(
final By locator) {
return new Function() {
@Override
public WebElement apply(WebDriver driver) {
return driver.findElement(locator);
}
};
}
// Read Data From Excel
public void GetDataFromExcel() throws Exception {
// Creating an instance for the test data file.
FileInputStream fis = new FileInputStream("C:\\TestData.xls");
// Assigning above instance value to a work book variable (workbook).
Workbook workbook = Workbook.getWorkbook(fis);
// Select the sheet from the workbook.
Sheet sheet = workbook.getSheet("Sheet1");
for (int row = 0; row < sheet.getRows(); row++) {
ArrayList arrayList = new ArrayList();
for (int col = 0; col < sheet.getColumns(); col++) {
String st = sheet.getCell(col, row).getContents();
if (st.trim().length() == 0) {
break;
}
arrayList.add(st);
System.out.println(st);
}
systemVendorDTO = new SystemVendorDTO();
systemVendorDTO.setSystemCode(arrayList.get(0));
systemVendorDTO.setSystemOID(arrayList.get(1));
systemVendorDTO.setSystemName(arrayList.get(2));
systemVendorDTO.setNameSpace(arrayList.get(3));
systemVendorDTO.setDescription(arrayList.get(4));
vendors.add(systemVendorDTO);
}
}
@AfterClass
public void teardown() {
driver.quit();
}
public static void main(String[] args) throws Exception {
AddSystemVendor obj = new AddSystemVendor();
obj.StartUp();
obj.OpenApplication();
obj.GetDataFromExcel();
obj.SaveSystemVendorMethod();
obj.teardown();
}
}
I don't know what did I do? Please help me to solve this problem.
Thanks in Advance!
I have written a java code for adding 'vendor' information thru our web application (i.e URL).
The script will perform the following:
1. Open up Application - Java Method Name : OpenApplication();
2. Read Data from Excel spreadsheet - Java Method Name : GetDataFromExcel()
3. Add Vendor - Java Method Name : SaveSystemVendorMethod()
In Excel spreadsheet, there are TWO rows available. Script is running successfully till the TWO rows fetched from the excel and added successfully. After that, it is displaying the following error message.
" Element not found in the cache - perhaps the page has changed since it was looked up "
I tried with implicit wait method like this.
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
But, it is not working. See my complete source code.
DTO Class:
public class SystemVendorDTO {
private String SystemCode;
private String SystemOID;
private String SystemName;
private String NameSpace;
private String Description;
public SystemVendorDTO() {
}
public SystemVendorDTO(String systemCode, String systemOID,
String systemName, String nameSpace, String description) {
SystemCode = systemCode;
SystemOID = systemOID;
SystemName = systemName;
NameSpace = nameSpace;
Description = description;
}
public void setSystemCode(String systemCode) {
this.SystemCode = systemCode;
}
public String getSystemCode() {
return SystemCode;
}
public void setSystemOID(String systemOID) {
this.SystemOID = systemOID;
}
public String getSystemOID() {
return SystemOID;
}
public void setSystemName(String systemName) {
this.SystemName = systemName;
}
public String getSystemName() {
return SystemName;
}
public void setNameSpace(String nameSpace) {
this.NameSpace = nameSpace;
}
public String getNameSpace() {
return NameSpace;
}
public void setDescription(String description) {
this.Description = description;
}
public String getDescription() {
return Description;
}
}
Main Class:
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import jxl.Sheet;
import jxl.Workbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.google.common.base.Function;
public class AddSystemVendor {
private WebDriver driver;
private ArrayList
SystemVendorDTO systemVendorDTO;
@BeforeClass
public void StartUp() throws Exception {
driver = new FirefoxDriver();
http://this.GetDataFromExcel();
}
@Test(testName = "Open Application")
public void OpenApplication() {
driver.get("http://10.0.25.122:8090/hie");
WebElement mnuElement = driver.findElement(By
.xpath("//div[@id='j_idt10:j_idt11']/ul/li[7]/a/span[2]"));
WebElement submnuElement = driver.findElement(By
.xpath("//a[@id='j_idt10:j_idt36']/span[2]"));
try {
Actions builder = new Actions(driver);
// Move cursor to the Main Menu Element
builder.moveToElement(mnuElement).build().perform();
submnuElement.click();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.navigate().refresh();
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
// Reset input fields
public void ClearInputFields(ArrayList
WebDriverWait wait = new WebDriverWait(driver, 10);
for (int i = 0; i < 5; i++) {
wait.until(presenceOfElementLocated(By.id(elements.get(i))));
driver.findElement(By.id(elements.get(i))).clear();
}
}
@Test(description = "Add System Vendor")
public void SaveSystemVendorMethod() throws Exception {
for (SystemVendorDTO vendor : vendors) {
ArrayList
// Fill all the mandatory fields and click submit button
driver.findElement(By.id("j_idt51:systemCode")).sendKeys(
vendor.getSystemCode());
driver.findElement(By.id("j_idt51:systemOID")).sendKeys(
vendor.getSystemOID());
driver.findElement(By.id("j_idt51:SystemName")).sendKeys(
vendor.getSystemName());
driver.findElement(By.id("j_idt51:nameSpace")).sendKeys(
vendor.getNameSpace());
driver.findElement(By.id("j_idt51:description")).sendKeys(
vendor.getDescription());
// Click on Add System Vendor Button click
driver.findElement(By.name("createVendor")).click();
System.out.println(vendor.getSystemCode());
System.out.println("System Vendor Added Successfully");
// Add elements id into ArrayList
elements.add("j_idt51:systemCode");
elements.add("j_idt51:systemOID");
elements.add("j_idt51:SystemName");
elements.add("j_idt51:nameSpace");
elements.add("j_idt51:description");
// Reset the input fields
ClearInputFields(elements);
}
}
private static Function
final By locator) {
return new Function
@Override
public WebElement apply(WebDriver driver) {
return driver.findElement(locator);
}
};
}
// Read Data From Excel
public void GetDataFromExcel() throws Exception {
// Creating an instance for the test data file.
FileInputStream fis = new FileInputStream("C:\\TestData.xls");
// Assigning above instance value to a work book variable (workbook).
Workbook workbook = Workbook.getWorkbook(fis);
// Select the sheet from the workbook.
Sheet sheet = workbook.getSheet("Sheet1");
for (int row = 0; row < sheet.getRows(); row++) {
ArrayList
for (int col = 0; col < sheet.getColumns(); col++) {
String st = sheet.getCell(col, row).getContents();
if (st.trim().length() == 0) {
break;
}
arrayList.add(st);
System.out.println(st);
}
systemVendorDTO = new SystemVendorDTO();
systemVendorDTO.setSystemCode(arrayList.get(0));
systemVendorDTO.setSystemOID(arrayList.get(1));
systemVendorDTO.setSystemName(arrayList.get(2));
systemVendorDTO.setNameSpace(arrayList.get(3));
systemVendorDTO.setDescription(arrayList.get(4));
vendors.add(systemVendorDTO);
}
}
@AfterClass
public void teardown() {
driver.quit();
}
public static void main(String[] args) throws Exception {
AddSystemVendor obj = new AddSystemVendor();
obj.StartUp();
obj.OpenApplication();
obj.GetDataFromExcel();
obj.SaveSystemVendorMethod();
obj.teardown();
}
}
I don't know what did I do? Please help me to solve this problem.
Thanks in Advance!
Re: Can anyone help me to resolve the cache error in selenium webdriver?
Fri May 31, 2013 10:15 am
I did not have chance to go through entire code, but which line throws this error -
" Element not found in the cache - perhaps the page has changed since it was looked up "
?
" Element not found in the cache - perhaps the page has changed since it was looked up "
?
- mail2prassadAmateur
- Posts : 41
Join date : 2013-06-05
Re: Can anyone help me to resolve the cache error in selenium webdriver?
Wed Jun 05, 2013 10:25 pm
Can you please post the complete stack trace.
- Selenium IDE showing error in click command.. hw to resolve this error
- Error : I could not able to switch parent window to overlay window because that it throws No element exception found. We are using the webdriver :- 2.45.1 Please some one can help to resolve this issue, thanks in advance.
- Selenium Webdriver: Unable to Locate element Link method error
- How to resolve this error---->[error] Element id=ui-active-menuitem not found
- RESOLVED: Selenium Webdriver - SSL certificate error on IE8
Permissions in this forum:
You cannot reply to topics in this forum