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.
Auf dieser Seite können Sie das Online-Video How to Handle Tooltip in Selenium WebDriver | Selenium - Java mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer CodeWithAvadoot 14 März 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 688 Mal angesehen und es wurde von 9 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!