I'm trying to get the tooltip text on the search results in www.bigbasket.com and have used the below code
@FindAll({@FindBy(xpath="//*[contains(@id,'product')][not(contains(@style,'display:none'))]/div/span[2]/a")})
List<WebElement> lblProductName;
public String verifySearchResults(WebDriver browser, String productName){
System.out.println(lblProductName.size());
try{
Actions actions = new Actions(browser);
for(WebElement eachElement:lblProductName){
System.out.println(eachElement.getAttribute("href"));
actions.moveToElement(eachElement).perform();
//Actions action = new Actions(driver);
actions.moveToElement(eachElement).build().perform();
WebElement toolTipElement = browser.findElement(By.cssSelector(".uiv2-tool-tip-hover "));
System.out.println("Tooltip text is "+toolTipElement.getAttribute("textContent"));
}
}catch(Exception e){
System.out.println(e.getMessage());
}
return productName;
}
But with the above code I'm able to get only the tool tip text of the first search result. Could you please help me in how to get the tool tip text of all search results?
Manual steps to follow 1. Go to www.bigbasket.com 2. Click Skip and Explore button 3. Search Apple 4. Mouse over each of the search result and view the tool tip text
One thing I could observe is there are multiple
tool-tip-hoverelements where in you are using :Instead you shall either use this as
OR
I would suggest creating a parent and further accessing its child (you can put it in the code flow accordingly) :
Note : Also I am not sure what role your actions shall be playing here. I doubt there presence to get the details over hovering. Just try once to ignore them.