-2

I need to read the text with the tooltip, I've tried a lot of ways and I always get the result that I can't find that element (selenium-java)

https://demoqa.com/tool-tips

enter image description here

bad_coder
  • 11,289
  • 20
  • 44
  • 72

1 Answers1

0

To inspect tooltip's html code you need to freeze the dom -> Freeze screen in chrome debugger / DevTools panel for popover inspection?

Code:

package selenium;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

public class TooltipTest extends WebDriverSetup {

    public static void main(String[] args) {
        WebDriver driver = startChromeDriver(); // wrapped driver init
        driver.get("https://demoqa.com/tool-tips");
        WebElement toolTipButton = driver.findElement(By.id("toolTipButton"));
        Actions action = new Actions(driver);
        action.moveToElement(toolTipButton).perform();
        WebElement tooltip = driver.findElement(By.className("tooltip-inner"));
        System.out.println(tooltip.isDisplayed());
        System.out.println(tooltip.getText());
        driver.quit();
    }
    
}

Output:

Starting ChromeDriver 92.0.4515.43 (8c61b7e2989f2990d42f859cac71319137787cce-refs/branch-heads/4515@{#306}) on port 25112
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Zář 03, 2021 8:52:54 DOP. org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
true
You hovered over the Button
pburgr
  • 1,722
  • 1
  • 11
  • 26