What is Tooltip?

Tooltip is an information about some web element which appears when user moves cursor on that web element if tool tip is assigned to that web element. It helps user to understand meaning of web element. For example: There is a registration form and it contains some fields. User who has idea about all fields , they can fill it easily. For user who has no idea of every fields, they can mouse hover on element and see information about particular fields. [Note: Developer needs to provide tooltip.]

We can create tooltips using CSS, bootstrap, JQuery etc. In this post we will learn how can we handle bootstarp tool tip in selenium webdriver.

Scenario to be automated:

Out task is to fetch the text from tool tip and print. Once you fetch, you can do whatever validation you desire.

Since, tooltip appears when we mouse hover, we can inspect it on appearance. Problem is that as soon as you move cursor out of web element, tooltip will be invisible. To inspect tooltip , follow below steps:

1. Mouse hover on web element which has tool tip till tooltip appears on screen.
2. Press F8 or Fn+F8(As per your system). It will pause the UI with tooltip visible.
3. Now click on inspector icon and drop on tooltip. You will get html code for tool tip element. See picture below:

To move cursor over element to make tooltip visible, we will use Actions class and its methods.

Once we mouse hove on element, after some seconds/milliseconds (depends) tooltip will be visible.

So, we need to use explicit wait here to make webdriver wait till tooltip is visible.

Once tooltip is visible, we will use getText() method to fetch tooltip text.

Java Code:

Page Object class:

Test script to find tool tip:

Output:

If you have any doubt, feel free to ask here.

If you like my posts, please like, comment, share and subscribe.

#ThanksForReading

#HappySelenium

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning