I have 5 elements which I am tryin to hover 1 by 1. I am putting these elements in a List. But when I use List for Hover(with and without loop) it gives Stale Element Exception. Note I can perform it when I use individual elements without using list. I have printed the elements from List and the xpath returned also looks correct.
System.out.println("=====================All star start ================");
Actions actions= new Actions(driver);
List<WebElement> starList= new ArrayList<WebElement>();
ArrayList<WebElement> starColorList= new ArrayList<WebElement>();
Reporter.log("Started adding star elements", true);
for(i=11,j=22;i<=15;i++,j=j+2)
{
Reporter.log("Started adding star elements"+i+j, true);
WebElement s = driver.findElement(By.xpath("(//*[name()='svg'][@class='rvs-star-svg'])["+i+"]"));
WebElement sc = driver.findElement(By.xpath("(//*[name()='svg']//*[name()='path'])["+j+"]"));
starList.add(s);
starColorList.add(sc);
}
//Does not work even without loop
actions.moveToElement(starList.get(2)).build().perform();
//Works actions.moveToElement(star1).build().perform();
Does not work for(i=0;i<starList.size();i++) {
Reporter.log("Started Hover"+i, true);
actions.moveToElement(starList.get(i)).build().perform();
Thread.sleep(2000);
System.out.println(starList.get(i));
//System.out.println("Star"+i+"has color "+starColorList.get(i).getAttribute("stroke"));
}
'''