Question: I am trying to write a Selenium test against Amazon site. I want to get "Sign in" element so that I can click on it.

url: www.amazon.es

Here is my Selenium Code:

```
System.setProperty("webdriver.gecko.driver","C:\\geckodriver-v0.18.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.amazon.es");

try
{           
    driver.findElement(By.id("nav-link-accountList")).click();
}
catch (Exception e)
{
    System.out.println("Not Found");
}

```

Sometimes the code works correctly but sometimes it does not find the ID "nav-link-yourAccount". What is the problem? and how can I solve it?

Answer: 
Apply wait until element is appeared, so that it avoids **NoSuchElementException** and code is working without any error.

Below code is working fine:

```
driver.get("https://www.amazon.es");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebElement accontButton=driver.findElement(By.id("nav-link-accountList"));
WebDriverWait waitforelement=new WebDriverWait(driver,20);
waitforelement.until(ExpectedConditions.elementToBeClickable(accontButton));
try{           
accontButton.click();
}

catch (Exception e){
System.out.println("Not Found");
}

```
Have you tried to find elements by xpath?

```
System.setProperty("webdriver.gecko.driver","C:\\geckodriver-v0.18.0-win64\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.amazon.es");

try
{           
        driver.findElement(By.xpath("//*[@id='nav-link-accountList']")).click();

}catch (Exception e)
 {
        System.out.println("Not Found");

    }

```