'stale element reference: while trying to access a drop down button

Have been trying to access the drop down button element using selenium, the page asks for a pincode on opening and after entering it and clicking ok it refreshes and then when i try to find the element by id or class name or css selector it throws an exception stating " stale element reference: element is not attached to the page document ", It will be helpful to know where im going wrong with the following code, Thanx in advance !

here is my code :

    package introduction;

    import java.time.Duration;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;

    public class Locators {

    public static void main(String[] args)  {
    // TODO Auto-generated method stub
    
    
    System.setProperty("webdriver.chrome.driver", "D:/Temp/chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
    driver.get("https://v5.fipola.in/");
    driver.findElement(By.id("DelLocation")).sendKeys("600020");
    driver.findElement(By.className("top_pincode_select")).click();
    driver.findElement(By.className("customer-name")).click(); //error on this line
    
    }
  }

image with the dom

I solved it by introducing thread.sleep(3000) line with interrupted exception on void main, but my question is why does the driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5)); did not work ? does that suppose to make the webdriver wait for 5 seconds until the page gets reloaded after entering the pincode and click ok ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source