Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» FlexMonkium Download Not available under Gorillalogic site
Thu Dec 08, 2016 5:40 pm by bhanu.praveen

» Selenium Script issue
Tue Dec 06, 2016 9:48 pm by njain213

» Difference between QTP, Selenium and Silk test
Tue Dec 06, 2016 7:58 pm by jessicacyrus1

» Where does selenium script pick browser from
Tue Dec 06, 2016 1:52 pm by janbaskt

» Safari throws an HTTP ERROR: 404
Tue Dec 06, 2016 1:51 pm by janbaskt

» Access Denied Error in Selenium RC
Tue Dec 06, 2016 1:51 pm by janbaskt

» Automating Flex application through selenium webdriver
Fri Dec 02, 2016 2:06 pm by abhinay.krs

» Starting with Selenium, what is Selenium?
Mon Nov 28, 2016 4:00 pm by Foma

» Getting started with Selenium
Mon Nov 28, 2016 3:23 pm by Rebbelx

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Can anyone help me to resolve the cache error in selenium webdriver?

View previous topic View next topic Go down

Can anyone help me to resolve the cache error in selenium webdriver?

Post by gkpandi on 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!

gkpandi
Active particpant
Active particpant

Posts : 14
Join date : 2013-05-23

Back to top Go down

Re: Can anyone help me to resolve the cache error in selenium webdriver?

Post by tarun3kumar on 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 "


?

_________________
Thanks
Tarun K
Free Selenium Training

tarun3kumar
Master
Master

Posts : 186
Join date : 2012-02-14

http://seleniumtests.com

Back to top Go down

Re: Can anyone help me to resolve the cache error in selenium webdriver?

Post by mail2prassad on Wed Jun 05, 2013 10:25 pm

Can you please post the complete stack trace.

mail2prassad
Amateur
Amateur

Posts : 41
Join date : 2013-06-05

Back to top Go down

Re: Can anyone help me to resolve the cache error in selenium webdriver?

Post by Sponsored content Today at 11:58 am


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum