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

14,303

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");
Share:
14,303
user3388456
Author by

user3388456

Updated on June 04, 2022

Comments

  • user3388456
    user3388456 almost 2 years

    "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

  • user3388456
    user3388456 about 10 years
    It worked out when the element is identified again in the same driver.. But a modal dialog is shown after logout and url is loaded again
  • Alam
    Alam over 8 years
    I don't know whether it's good practice to get the value of element again or not, but it works. Thank you!
  • Aravin
    Aravin over 8 years
    Well explained. Is there any documentation about this? @mfsi