In this video, I have explained about how we can handle tooltip in Selenium WebDriver.
Example :
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
Actions actions = new Actions(driver);
WebElement tooltipOnButton = driver.findElement(By.id("toolTipButton"));
actions.moveToElement(tooltipOnButton).build().perform();
wait.until(ExpectedConditions.presenceOfElementLocated(
By.xpath("//*[text()='You hovered over the Button']")));
WebElement tooltipTextOnButton =
driver.findElement(By.xpath("//*[text()='You hovered over the Button']"));
String tooltipText = tooltipTextOnButton.getText();
System.out.println(tooltipText);
WebElement tooltipTextOnInputField = driver.findElement(By.id("toolTipTextField"));
actions.moveToElement(tooltipTextOnInputField).build().perform();
wait.until(ExpectedConditions.presenceOfElementLocated(
By.xpath("//*[text()='You hovered over the text field']")));
WebElement tooltipTextInputField =
driver.findElement(By.xpath("//*[text()='You hovered over the text field']"));
String tooltipText1 = tooltipTextInputField.getText();
System.out.println(tooltipText1);
WebElement tooltipOnAnchorTag = driver.findElement(By.xpath("//*[text()='Contrary']"));
actions.moveToElement(tooltipOnAnchorTag).build().perform();
wait.until(ExpectedConditions.presenceOfElementLocated(
By.xpath("//*[text()='You hovered over the Contrary']")));
WebElement tooltipTextAnchorTag =
driver.findElement(By.xpath("//*[text()='You hovered over the Contrary']"));
String tooltipText2 = tooltipTextAnchorTag.getText();
System.out.println(tooltipText2);
***** Methods we will be using *****
1) moveToElement(element): of Actions class is used to mouse hover an element.
2) Build(): method of Actions class builds the sequence of user actions into an Action object.
3) Perform(): of Action class executes all the sequence of user actions at once.
4) getText(): to get the tooltip text.
On this page of the site you can watch the video online How to Handle Tooltip in Selenium WebDriver | Selenium - Java with a duration of hours minute second in good quality, which was uploaded by the user CodeWithAvadoot 14 March 2021, share the link with friends and acquaintances, this video has already been watched 688 times on youtube and it was liked by 9 viewers. Enjoy your viewing!