I am unable to get the tool tip from a tag. The snippet of the HTML is

  <table class="tiger-stripe" width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr class="oddrow">
  <div id="div_2" class="betterTip fltlt">
   <p id="a_2" class="betterTip" lang="$div_2_Tip?width=300" title="">
  <div id="div_2_Tip" class="ToolTip" style="display:none">
  <p class="Tooltip">Evaluate value : 400.00</p>
  <p class="Tooltip">Actual value : 646.69</p>
 <p class="Tooltip">Description : Payment Amount Back must be < Max Payment.</p>

Here in the above html code the tool tip location is in the first paragraph tab but the tool tip text is present in the next paragraph tag

I am trying to get the tool tip from various methods like getText(), getAttribute() but no use. Can any one help me out?enter image description here

Code :

Actions a =new Actions(driver);    


String toolTipText1= driver.findElement(By.xpath("//table[@class='tiger-stripe']/tbody/tr[2]/td[2]/di‌v[@id='div_2']/p[@id='a_2']")).getAttribute("title"); 

System.out.println("tool tip text: "+toolTipText1)
  • what code you have written? – Helping Hands Sep 4 '15 at 9:10
  • Actions a =new Actions(driver); a.moveToElement(driver.findElement(By.xpath("//table[@class='tiger-stripe']/tbody/tr[2]/td[2]/div[@id='div_2']/p[@id='a_2']"))).perform(); String toolTipText1 = driver.findElement(By.xpath("//table[@class='tiger-stripe']/tbody/tr[2]/td[2]/div[@id='div_2']/p[@id='a_2']")).getAttribute("title"); System.out.println("tool tip text: "+toolTipText1) – Bunny Sep 4 '15 at 9:25
  • please don't concentrate on the code, i have attached the html snap, check it once – Bunny Sep 4 '15 at 9:26
  • Seems you are using incorrect xpath – Helping Hands Sep 4 '15 at 10:08

Your xpath doesn't seem to be correct.

String toolTipText1= driver.findElement(By.xpath("//table[@class='tiger-stripe']/tbody/tr[2]/td[2]/di‌v[@id='div_2']/p[@id='a_2']")).getAttribute("title");

If you see your HTML, the text that is shown in the tooltip is contained in another div id then what you are using. Also, you're trying to get the title attribute, which as per the HTML is blank.

Try using this

   String toolTipText1= driver.findElement(By.xpath("//table[@class='tiger-stripe']/tbody/tr[2]/td[2]/di‌v[@id='div_2_Tip']/p[@class='Tooltip']")).getText();
| improve this answer | |
  • I tried earlier, no it is not working, please give me a solution – Bunny Sep 4 '15 at 13:53
  • what are you gwtting when you're using this – demouser123 Sep 4 '15 at 15:38
  • Nothing, null is getting as a value – Bunny Sep 9 '15 at 11:13
  • String toolTipText1= driver.findElement(By.xpath("//table[@class='tiger-stripe']/tbody/tr[2]/td[2]/di‌v[@id='div_2_Tip']/p[1]. getText( ) does this print anything? – demouser123 Sep 9 '15 at 11:52
  • yes it prints "null" as a value – Bunny Sep 10 '15 at 6:13

You have to use Actions for this. in this am printing the mouse hover message in Google

    Actions ToolTip1 = new Actions(driver);
    WebElement googleLogo = driver.findElement(By.xpath("//div[@id='hplogo']"));



Perform mouse hover action using 'clickAndHold' method.

Get the value of Tool tip by using 'getAttribute' command

    String ToolTipText = googleLogo.getAttribute("title");

    Assert.assertEquals(ToolTipText, "Google");

    System.out.println("Tooltip value is: " + ToolTipText);
| improve this answer | |

Try this:

List<WebElement> webElements=driver.findElements(By.xpath("//*[@class='Tooltip']"));   
         for(int i=0;i< webElements.size(); i++)   

This should print the text for all the tool-tips present here as the class name for all the tool-tips is "Tooltip"

| improve this answer | |

We use getAttribute("title"); to get the tooltip text of a webelement. In this please make sure that the webelement is not inside another iframe.

I found one more thing from the html snapshot you provided. That is the element is having an attribute called "title", whose value is "" (Empty string). So probably you will get printed the empty string.

If the above things followed and not solved your problem. Kindly let us know the exception thrown(if any).

| improve this answer | |

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