I am working in eclipse writing selenium scripts using Java. I am using the chrome web driver. I have a hyper text link that when I put my mouse over it hover text box appears. I need to return that string to verify it. How can I return that text in a string? The problem I am having is that I cannot put my mouse over the hover text box to find the element because the hover text box disappears so there is no way for me to just easily put the dev tools over the text box to get the text.

  • Just vote me down with give no reason, that should not be allowed. This is a valid question with all the relevant information and I checked the database for any duplicate questions so wtf. – 4m4d3u5 Jan 22 at 18:43
  • While I didn't down vote, my guess is missing code samples? It can be very helpful to see the code from the DOM you're working with and the code you're written to try to accomplish this task. – Lee Jensen Jan 22 at 21:45
  • Is it a question or statement , what's the actual problem – PDHide Jan 23 at 12:23
  • @PDHide "I have an element that is some text that I can hover over and that brings up a hover text box with a bunch of text in it. How can I get that text?" – 4m4d3u5 Jan 23 at 22:09
  • Did the answer help – PDHide Jan 24 at 20:28

Below is an example on how to get the text of tool tip:

    Actions builder = new Actions(driver);

    WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
    WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("tooltiptext")));

You have to use action class for hovering and use getText after using wait for visibility of .

html used for above example:

just copy this and save as an html file to try out

<!DOCTYPE html>
.tooltip {
  position: relative;
  display: inline-block;
  border-bottom: 1px dotted black;

.tooltip .tooltiptext {
  visibility: hidden;
  width: 120px;
  background-color: black;
  color: #fff;
  text-align: center;
  border-radius: 6px;
  padding: 5px 0;
  position: absolute;
  z-index: 1;
  bottom: 100%;
  left: 50%;
  margin-left: -60px;
  /* Fade in tooltip - takes 1 second to go from 0% to 100% opac: */
  opacity: 0;
  transition: opacity 1s;

.tooltip:hover .tooltiptext {
  visibility: visible;
  opacity: 1;
<body style="text-align:center;">

<h2>Fade In Tooltip on Hover</h2>
<p>When you move the mouse over the text below, the tooltip text will fade in and take 1 second to go from completely invisible to visible.</p>

<div class="tooltip">Hover over me
  <span class="tooltiptext">extract text</span>


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.