Element not found in the cache

35 views
Skip to first unread message

Bimlesh M

unread,
Jul 25, 2016, 3:02:25 AM7/25/16
to Selenium Users
Dear All,

I am trying to login to amazon website after giving valid user name and password. After successful login, I am searching for "Samsung Galaxy" and clicking the search button. Once the results are displayed, 
I am trying to narrow the search by entering min_amount = 30000 and max_amount = 40000 from the left side of the page but when I trying to enter a value in the min_price input field and max_price input field, I am getting "Element not found in the cache.." Kindly advise.

Exception - org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up Command duration or timeout: 45.08 seconds

public Amazon_Samsung_Galaxy_Search(WebDriver driver)
{
    this.driver=driver;

}

@FindBy (xpath = ".//input[@id='twotabsearchtextbox']") WebElement Product_Search;
@FindBy (xpath = "//input[@class='nav-input'][@type='submit']") WebElement Search_Click;
@FindBy (xpath = ".//*[@id='ref_1485076031']//img[@alt='Android']") WebElement Android_Check;
@FindBy (xpath = ".//*[@id='ref_3837712031']//img[@alt='Samsung']") WebElement Samsung_Check;
@FindBy (xpath = ".//*[@id='ref_8561098031']//img[@alt='3000 - 3999 mAh']") WebElement Battery_Check;
@FindBy (xpath = ".//*[@id='ref_6631751031']//img[@alt='5.5 Inches & Above']") WebElement Screen_Check;
@FindBy (xpath = ".//*[@id='ref_8561129031']//img[@alt='4 GB & More']") WebElement Ram_Check;
@FindBy (xpath = "//input[@id='low-price']") WebElement Low_Price;
@FindBy (xpath = "//input[@id='high-price']") WebElement High_Price;
@FindBy (xpath = "//input[@class='leftNavGoBtn']") WebElement GO_Button;
@FindBy (xpath = ".//span[@id='quartsPagelet']") WebElement Search_Result;


public void Search_Samsung_Galaxy()
{
    Product_Search.sendKeys("Samsung Galaxy");
    Search_Click.click();

    Samsung_Check.click();

    WebDriverWait wait = new WebDriverWait(driver, 30);
    WebElement Android_Check = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//*[@id='ref_1485076031']//img[@alt='Android']")));

    ((JavascriptExecutor)driver).executeScript("window.scrollTo(0,"+Android_Check.getLocation().x+")");

    Android_Check.click();

    WebDriverWait wait4 = new WebDriverWait(driver, 45);
    WebElement Low_Price = wait4.until(ExpectedConditions.visibilityOfElementLocated(By.id("low-price")));

    Coordinates cor = ((Locatable)Low_Price).getCoordinates();
    cor.inViewPort();

    Low_Price.sendKeys("30000");

    WebDriverWait wait5 = new WebDriverWait(driver, 30);
    WebElement High_Price = wait5.until(ExpectedConditions.visibilityOfElementLocated(By.id("high-price")));

    Coordinates cor1 = ((Locatable)High_Price).getCoordinates();
    cor1.inViewPort();

    High_Price.click();
    High_Price.sendKeys("40000");

    WebDriverWait wait6 = new WebDriverWait(driver, 30);
    WebElement GO_Button = wait6.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@class='leftNavGoBtn']")));

    Coordinates cor2 = ((Locatable)GO_Button).getCoordinates();
    cor2.inViewPort();

    GO_Button.click();


}
Reply all
Reply to author
Forward
0 new messages