How to Handle Tooltip in Selenium WebDriver | Selenium - Java

Опубликовано: 14 Март 2021
на канале: 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.


На этой странице сайта вы можете посмотреть видео онлайн How to Handle Tooltip in Selenium WebDriver | Selenium - Java длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь CodeWithAvadoot 14 Март 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 688 раз и оно понравилось 9 зрителям. Приятного просмотра!