There are seven images. I want to do mouse hover on every image and and check AddToCart button is displayed or not. I have tried following code and it is not working.
Reference: http://automationpractice.com/index.php
public boolean checkMouseHoveronAllItems(WebDriver driver)
{
String xpathOfItems="//[@id='homefeatured']/li['+index+']/div/div[1]/div/a[1]/img";
String xpathOfAddToCartButtons="//div[@class='button-container']/a[@title='Add to cart']";
boolean res=false;
for(int index=1;index<=countNoOfItems(driver);index++)
{
element=driver.findElement(By.xpath(xpathOfItems));
performMouseHover(element);
System.out.println("Item By index"+element.getAttribute("alt"));
element=element.findElement(By.xpath(xpathOfAddToCartButtons));
if(element.isDisplayed())
{
res=true;
Log.info("Element is available");
}
else
{
res=false;
}
}
return res;
}
Code always taking the fist element and printing the alt attribute text.