How to Handle Tooltip in Selenium WebDriver | Selenium - Java

Publicado em: 14 Março 2021
no canal de: CodeWithAvadoot
688
9

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.


Nesta página do site você pode assistir ao vídeo on-line How to Handle Tooltip in Selenium WebDriver | Selenium - Java duração hora minuto segundo em boa qualidade , que foi baixado pelo usuário CodeWithAvadoot 14 Março 2021, compartilhe o link com seus amigos e conhecidos, no youtube este vídeo já foi visto 688 vezes e gostou 9 espectadores. Boa visualização!