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)
Asked
Active
Viewed 195 times
-2
-
Can you share at least *one* of the "lot of ways" you have tried to solve this? – Scott Hunter Sep 02 '21 at 18:21
-
Try to find with partialLinkText, xpath, class. String tooltipTxt = driver.findElement(By.xpath("xpath")).getAttribute("title"); All time is problem because selenium cant to locate element. by LinkText – milan cajic Sep 02 '21 at 18:53
-
https://demoqa.com/tool-tips – milan cajic Sep 02 '21 at 18:57
1 Answers
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