title: Retrieve Tool tip text from Selenium WebDriver in Java
body: <p>I have written below code to retrieve tooltip text from an application. But it's always passing the value as empty.("")
  Assume the application is ToolsQA "<a href="http://demoqa.com/" rel="nofollow noreferrer">http://demoqa.com/</a>" and I want to take the tooltip text of the <a href="http://demoqa.com/tooltip/" rel="nofollow noreferrer">http://demoqa.com/tooltip/</a> "Your age"</p>
  
  <p>Please see the code below which I used.</p>
  
  <pre><code>public String  getToolTipText(String xpath) throws InterruptedException{
  
          xpath = "//div[@class='inside_contain']//input";
          WebElement mainElement = driver.findElement(By.xpath(xpath));
          Actions act = new Actions(driver);
          //act.moveToElement(mainElement).build().perform();
          act.clickAndHold(mainElement).build().perform(); 
          Thread.sleep(5000);
          String tooltiptextreal = mainElement.getAttribute("title");
  
          return tooltiptextreal;
      }
  </code></pre>
  
  <p>Assertion: </p>
  
  <pre><code>String TooltipText = "We ask for your age only for statistical purpose.";
      Assert.assertEquals(pToolsQAWidgetTooltipPageDom.getToolTipText(), TooltipText);
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>java.lang.AssertionError: expected [We ask for your age only for statistical purpose.] but found []
  </code></pre>