I need to verify if hover over is working for a webelement using selenium. I know there are lots of answers asking to use either action class or getTitle().For ex: https://www.guru99.com/verify-tooltip-selenium-webdriver.html In both these solutions, it is about getting the text and asserting it. But my question is how can it ensure that hover over is working (I mean, when the user does a hover over the tooltip text should be displayed). For ex: in the below code, Actions class is used to clickAndHold and moveToElement. And then getText() is done to get the hover over text. Isn't the end result the same as using WebElement.getText() without using Actions class?
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.*;
public class JqueryToolTip {
public static void main(String[] args) {
String baseUrl = "http://demo.guru99.com/test/tooltip.html";
System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
String expectedTooltip = "What's new in 3.2";
driver.get(baseUrl);
WebElement download = driver.findElement(By.xpath(".//*[@id='download_now']"));
Actions builder = new Actions (driver);
builder.clickAndHold().moveToElement(download);
builder.moveToElement(download).build().perform();
WebElement toolTipElement = driver.findElement(By.xpath(".//*[@class='box']/div/a"));
String actualTooltip = toolTipElement.getText();
System.out.println("Actual Title of Tool Tip "+actualTooltip);
if(actualTooltip.equals(expectedTooltip)) {
System.out.println("Test Case Passed");
}
driver.close();
}
}