Hello All Selenium Users,
I need some expertise to help me out.
I have been searching and trying different approaches the best one I found is this:
WebDriver driver= new ChromeDriver();
Thread.sleep(6000);
driver.findElement(By.xpath("//*[@id='gbqfq']")).sendKeys("SanDisk 32 GB Memory Card");
driver.findElement(By.xpath("//*[@id='gbqfb']/span")).click();
List<String> hrefs = new ArrayList<String>();
List<WebElement> links = driver.findElements(By.tagName("a"));
Iterator<WebElement> i = links.iterator();
while(i.hasNext()) {
WebElement link = i.next();
hrefs.add(link.getAttribute("href"));
}
Iterator<String> j = hrefs.iterator();
while(j.hasNext()) {
String href = j.next();
WebElement link = driver.findElement(By.cssSelector("a[href=" + href +"]"));
link.click();
// confirm the link was good
driver.navigate().back();
}
This block of code returns all the links fetched but gives this error :
"message": "stale element reference: element is not attached to the page document\n (Session info: chrome=30.0.1599.69)\n (Driver info: chromedriver=2.0,platform=Windows NT 6.1 SP1 x86_64)"
I think there should be a better approach like fetching all the links then depositing it into an array and then just loop through that array.
I am using selenium webdriver 2.35 with java.
Please help me if possible!
Regards,
Mediha