Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

0
StaleElementReferenceException Java- selenium

Solved 1 Answers 305 Views Selenium
0 1
I am getting StaleElementReferenceException when I run my code on Flipkart website for selecting "Buy NOW" .
 
 
public void SelectItemfromPage(){
 
    WebDriver driver = new FirefoxDriver();
 
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get("http://www.flipkart.com");
    WebElement element = driver.findElement(By.xpath(".//*[@id='fk-top-search-box']"));
    element.sendKeys("moto g");
    element.submit();
 
 
    element.findElement(By.xpath(".//*[@id='products']/div/div[1]/div[1]/div/div[1]/a[1]/img")).click();
    element.findElement(By.xpath(".//*[@id='fk-mainbody-id']/div/div[7]/div/div[3]/div/div/div[6]/div/div[3]/div[1]/div/div[2]/div/div[2]/form/input[9]")).click();
}

1 Answer

0
Best answer
0

You are submitting a page and again trying to work on element identified before submitting. Your code should be as below.

 

WebDriver driver = new FirefoxDriver();
 
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get("http://www.flipkart.com");
    WebElement element = driver.findElement(By.xpath(".//*[@id='fk-top-search-box']"));
    element.sendKeys("moto g");
    element.submit();
 
 
    driver.findElement(By.xpath(".//*[@id='products']/div/div[1]/div[1]/div/div[1]/a[1]/img")).click();
    driver.findElement(By.xpath(".//*[@id='fk-mainbody-id']/div/div[7]/div/div[3]/div/div/div[6]/div/div[3]/div[1]/div/div[2]/div/div[2]/form/input[9]")).click();
answered by
selected by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
...