• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • Home
  • Programming Languages
    • Java Tutorials
    • Python Tutorials
    • JavaScript Tutorials
  • Automation Tools and Different Tools
    • Web Automation
      • Selenium with Java
        • Selenium Basic
        • Selenium Advance
        • Selenium Realtime
        • Framework
        • Selenium Interview
        • Selenium Videos
        • Selenium with Docker
      • Selenium with Python
      • WebdriverIO
        • Selenium Webdriver C# Tutorial
      • Cypress
      • Playwright
    • TestNG
    • Cucumber
    • Mobile Automation
      • Appium
    • API Testing
      • Postman
      • Rest Assured
      • SOAPUI
    • testRigor
    • Katalon
    • TestProject
    • Serenity BDD
    • Gradle- Build Tool
    • RPA-UiPath
    • Protractor
    • Windows Automation
  • Automation For Manual Testers
  • Services
  • Online Training
  • Contact us
  • About me
  • Follow us
    • Linkedin
    • Facebook Group
    • Facebook Page
    • Instagram

Automation

Selenium WebDriver tutorial Step by Step

You are here: Home / Basic Selenium / How to Capture Tooltip in Selenium Webdriver

How to Capture Tooltip in Selenium Webdriver

October 3, 2020 by Mukesh Otwani 20 Comments

This article will help you to understand How to Capture Tooltip in Selenium Webdriver and how we can verify the same in our automated test.

Tooltip sometime is also known as Help text.

When we use mouse hover on some element or click on some element then this tooltip comes. Here is a quick example of help text or tooltip.
Capture tooltip in Selenium

 

Example- Example of Gmail, when we create a new account and fill some fields than for elements you will get the warning or help text.

 

How to Capture Tooltip in Selenium Webdriver

Approach to capture tooltip message in Selenium

  • In this example first, open Gmail account.
  • Click on username then tooltip message will appear.
  • Then mouse hover on the message
  • Capture that message in a String variable and print.
  • Then use TestNG Assertion to verify messages.

 

Program to implement-How to Capture Tooltip in Selenium Webdriver

package demo1;

 
import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.interactions.Actions;

 

public class Tooltip {

public static void main(String[] args) {

// This will open browser
 WebDriver driver=new FirefoxDriver();

// This will maximize your browser
driver.manage().window().maximize();

// Open gmail account creation page
 driver.get("https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ltmpl=default");

 // Click on username textbox
driver.findElement(By.xpath(".//*[@id='GmailAddress']")).click();

 // Create action class object
Actions builder=new Actions(driver);

// find the tooltip xpath
 WebElement username_tooltip=driver.findElement(By.xpath("html/body/div[2]/div[1]"));

// Mouse hover to that text message
builder.moveToElement(username_tooltip).perform();

// Extract text from tooltip
 String tooltip_msg=username_tooltip.getText();

// Print the tooltip message just for our refrences
 System.out.println("Tooltip/ Help message is "+tooltip_msg);

 }
}

 

Output-

 

How to Capture Tooltip in Selenium Webdriver

How to Capture Tooltip in Selenium

package demo1;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.interactions.Actions;

import org.testng.Assert;

public class Tooltip {

 public static void main(String[] args) {

 // This will open browser
WebDriver driver=new FirefoxDriver();

 // This will maximize your browser
driver.manage().window().maximize();

// Open Gmail account creation page
driver.get("https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ltmpl=default");

// Click on username textbox
driver.findElement(By.xpath(".//*[@id='GmailAddress']")).click();

// Create action class object
Actions builder=new Actions(driver);

// find the tooltip/helptext message xpath
WebElement username_tooltip=driver.findElement(By.xpath("html/body/div[2]/div[1]"));

// Mouse hover to that text
builder.moveToElement(username_tooltip).perform();

// Extract the text from tooltip using getText
String tooltip_msg=username_tooltip.getText();

 // Print the tooltip message
System.out.println("Tooltip message is "+tooltip_msg);

// This is expected message should come and store in variable
 String expected_tooltip="You can use letters, numbers, and periods.";

// It will compare if actual matches with expected then TC will fall else it will fail
Assert.assertEquals(tooltip_msg, expected_tooltip);

System.out.println("Message verifed");

            }

}

 

 

Output

How to Capture Tooltip in Selenium Webdriver

 

Thanks for visiting my blog. Please comment in case any issue.

Keep in touch. Have a nice day 🙂

 

Filed Under: Basic Selenium Tagged With: Tooltip

Reader Interactions

Comments

  1. Tejas says

    November 18, 2021 at 2:27 PM

    Hii

    I am unable to get the text of tooltip tried with above code. Selenium is not printing anything in the console. Below is my code

    Actions actions = new Actions(driver);
    WebElement menuOption = driver.findElement(By.xpath(“//*[@id=’reminderEmailSentDetails-A111′ and @class=’ReminderEmailSentIcon’]”));
    actions.moveToElement(menuOption).perform();
    WrapperFunctionUtilities.waitForTime(4000);
    System.out.println(“Done Mouse hover on reminder sent icon”);

    String expectedstring = menuOption.getText();
    Log.info(“Details are”+expectedstring);

    Selenium is only printing Details are in the console

    Reply
    • Mukesh Otwani says

      November 26, 2021 at 10:45 AM

      Hi Tejas,

      Please try in debug mode so that you will get exact details like what is the issue.

      Thanks
      Mukesh

      Reply
  2. Mukesh Otwani says

    February 25, 2021 at 4:16 PM

    Ramesh, it does not matter whether it is div tag, span tag. The concept is we need to capture text and validate the date.

    Reply
  3. Jayesh says

    October 19, 2020 at 4:09 PM

    Great article Mukesh !!!

    I’m facing challenge in handling captcha in one of my proj, can u suggest some tricks and techniques to handle the same.

    Reply
    • Mukesh Otwani says

      October 21, 2020 at 4:00 PM

      Hi Jayesh,

      Please go through the below links

      https://www.youtube.com/watch?v=0pjzLMbtimk

      Hope that these will clarify your doubts

      Reply
  4. SATVEER BAJWA says

    April 4, 2019 at 6:21 PM

    Hi Mukesh,
    I am trying to automate the tooptip message after hover the mouse on it , but I am not able to do it. Have some questions:
    1. Do we need to get the xpath of the tool right where user hover the mouse not the location where tooltip message will show? because in my webpage here is icon let say edit after hover the mouse on it shows tooltip message then I need to give xpath of edit icon right?

    Reply
    • Mukesh Otwani says

      April 5, 2019 at 1:46 PM

      Hi Satveer,

      Selenium always works on DOM elements. If you want to get text for tooltip, somehow you need to get corresponding locator on DOM based on which you can webdriver operation. Here first you need to mouse hover over required control on screen then wait for few seconds then check for locator property for tooltip.

      Reply
      • SATVEER BAJWA says

        April 5, 2019 at 7:59 PM

        Hi Mukesh,
        Thanks for your reply. Yes it works now, the script ran successfully but when the output printed in console that is only “Tooltip/ Help message is” . it doesn’t extract the message (+tooltip_msg1). or one more thing if we have multiple hover functions on the same page then I used same Create action class object Actions builder=new Actions(driver) multiple times . it ran successfully. is it correct?

        System.out.println(“Tooltip/ Help message is “+tooltip_msg6);

        Reply
        • Mukesh Otwani says

          April 5, 2019 at 9:59 PM

          Hi Satveer,

          If you are using same Actions class object then its good only.

          Reply
          • SATVEER BAJWA says

            April 5, 2019 at 10:52 PM

            Okay Thank you so much Mukesh. Please provide me solution for this the script ran successfully but when the output printed in console that is only “Tooltip/ Help message is” . it doesn’t extract the message (+tooltip_msg1).

            Thanks

          • Mukesh Otwani says

            April 5, 2019 at 11:55 PM

            Hi Satveer,

            Now a days, market is full of different types of ui components and libraries so without looking and working on web ui of application, I can’t provide any solid solution for this.

  5. Suresh says

    August 30, 2016 at 1:45 PM

    I found every time tool tip changes in DOM as it loads after clicking on text box in browser, so i used below , it works now

    // find the tooltip xpath
    WebElement username_tooltip=driver.findElement(By.xpath(“//div[contains(@id,’bubble’)]”));

    Reply
    • Mukesh Otwani says

      September 8, 2016 at 1:28 AM

      Cheers Suresh

      Reply
  6. Paras says

    June 2, 2016 at 4:52 PM

    Hi Mukesh,

    How to find the xpath of tool tip item, how did u do that ?

    Reply
    • Mukesh Otwani says

      June 4, 2016 at 12:44 AM

      use Mouse Hover and for xpath use firepath.

      Reply
  7. Manoj Kumar says

    April 29, 2016 at 6:58 PM

    Hello sir
    How to get the path for the tool-tip, I am not being able to locate it with the help of firebug or fire path?

    Reply
    • Raveendra says

      December 16, 2016 at 11:26 AM

      1) First Navigate to the Create Gmail account page

      2) using the xpath locate the CHOOSE YOUR USERNAME CheckBox By using the Firebug and perform click operation.

      driver.findElement(By.xpath(“//input[@id=’GmailAddress’]”)).click();

      3)After Clicking CheckBox u will get the Tool Tip Message

      4) locate the toolTip Meaage Box using The Xpath Directly or else using MouseHover ,

      Here i ve used the some Explicitwait

      WebDriverWait wait = new WebDriverWait(driver,5);
      WebElement Text;
      Text = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath(“html/body/div[3]”)));
      Thread.sleep(2000);
      System.out.println(Text.getText());

      For the time being i have used Explicitwait

      Hope it will helps you

      Reply
      • Mukesh Otwani says

        December 17, 2016 at 11:58 AM

        THanks Raveendra 🙂

        Reply
  8. krishnaveni says

    March 18, 2016 at 12:26 AM

    Hi mukesh,

    i just tried the tooltip code that you mentioned above. its working well.

    As well i tried with out using action class and that works well.

    so what is the need of using action class over here,can you please clarify..

    Thank you for the blog,which helps a lot

    you can see the code below…

    WebDriver driver = new FirefoxDriver();
    //Gmail account creation page
    driver.get(“https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ltmpl=default”);

    driver.manage().window().maximize();
    //click on user name filed

    driver.findElement(By.xpath(“.//*[@id=’GmailAddress’]”)).click();

    // create Action class object
    //Actions builder= new Actions(driver);
    //find the tool tip message xpath
    WebElement tooltip = driver.findElement(By.xpath(“html/body/div[3]”));
    //Mouse hoover to that text message
    //builder.moveToElement(tooltip).perform();
    //get the text
    String tooltip_message = tooltip.getText();

    System.out.println(“tooltip message here” + tooltip_message);

    Reply
    • Mukesh Otwani says

      March 18, 2016 at 5:41 PM

      Hi krishnaveni,

      Good to know it worked for you. We used Actions class for Mouse hover 🙂

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Free Selenium Videos

https://www.youtube.com/watch?v=w_iPCT1ETO4

Search topic

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?

Stay connected via Facebook

Stay connected via Facebook

Archives

Footer

Categories

Recent Post

  • Syllabus For Playwright Online Training Program
  • API Testing Using Postman And RestAssured
  • Disable Personalise Your Web Experience Microsoft Edge Prompt In Selenium
  • How To Fix Error: No tests found In Playwright
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse

Top Posts & Pages

  • Selenium Webdriver tutorial for beginners
  • How To Fix Eclipse Autocomplete Or Code Suggestion In Eclipse
  • Selenium Webdriver C# Tutorial
  • WHAT ARE YOUR EXPECTATIONS FROM US?