user3388456
user3388456

Reputation: 31

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

"Element not found in the cache - perhaps the page has changed since it was looked up" when I logout and try to login in the same page.

In the above case, login to application is successful, and when I logout from application, the login page is displayed again. Problem is: when I tried to login again in same page, it shows Element not found in the cache - perhaps the page has changed since it was looked up

Login Url (fresh, 1st time): //firco/en_US/ d Logput URL (where login page is displayed again): //firco/en_US/logout/

I want to use same driver (browser instance) for 1st and 2nd login.

public static void main(String[] args) 
WebDriver driver = new FirefoxDriver();
driver.get("//Continuity/en_US/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement uname = driver.findElement(By.xpath(".//*[@id='text-input-element-15']"));
WebElement pwd = driver.findElement(By.xpath("id('text-input-element-16')"));
WebElement busunit = driver.findElement(By.xpath("id('text-input-element-22')"));
WebElement login = driver.findElement(By.id("login-button"));
uname.sendKeys("RAGHU");
pwd.sendKeys("Hello00");
login.click();
WebElement LogoutButton = driver.findElement(By.xpath(".//*[@id='logout-button']"));
LogoutButton.click();
driver.get("//Continuity/en_US/");
uname.sendKeys("SUGU");

In above code I want to user uname at both 1st and 2nd login (after logout), in same driver

Upvotes: 3

Views: 14509

Answers (1)

Sitam Jana
Sitam Jana

Reputation: 3129

Web elements you stored before clicking on login button will not be present in cache after login because of page refresh or page changes. You need to again store these web elements in order to make them available again under cache. I have modified your code a bit which might help:

public static void main(String[] args) 
WebDriver driver = new FirefoxDriver();
driver.get("//Continuity/en_US/");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement uname = driver.findElement(By.xpath(".//*[@id='text-input-element-15']"));
WebElement pwd = driver.findElement(By.xpath("id('text-input-element-16')"));
WebElement busunit = driver.findElement(By.xpath("id('text-input-element-22')"));
WebElement login = driver.findElement(By.id("login-button"));
uname.sendKeys("RAGHU");
pwd.sendKeys("Hello00");
login.click();
WebElement LogoutButton = driver.findElement(By.xpath(".//*[@id='logout-button']"));
LogoutButton.click();
driver.get("//Continuity/en_US/");
uname = driver.findElement(By.xpath(".//*[@id='text-input-element-15']"));
uname.sendKeys("SUGU");

Upvotes: 4

Related Questions