Professional Documents
Culture Documents
(https://www.guru99.com/)
Tooltips were traditionally implemented as a 'title' attribute to an element. The value of this
attribute was shown as a tooltip on mouse-hover. This is a static text giving information of
the element with no styling.
Now, there are many plugins available for 'tool tips' implementation. Advanced tooltips with
styling, rendering, images and links are being implemented using JavaScript/JQuery plugins
or using CSS Tooltips.
For accessing or verifying the static tooltips which are implemented using the HTML "title"
attribute, we can simply use the getAttribute("title") method of the WebElement. The
returned value of this method (which is the tooltip text) is compared with an expected
value for verification.
For other forms of tooltip implementations, we will have to use the "Advanced User
Interactions API" provided by the Web Driver to create the mouse hover effect and then
retrieve the tooltip for the element.
You can refer this link for more details on the API.
https://seleniumhq.github.io/selenium/docs/api/java/index.html?
org/openqa/selenium/interactions/Actions.html
(https://seleniumhq.github.io/selenium/docs/api/java/index.html?
org/openqa/selenium/interactions/Actions.html)
Here, let's see how to use a couple of classes and methods we would need to move a slider
element by an offset.
https://www.guru99.com/verify-tooltip-selenium-webdriver.html 1/10
Step
12/13/2018 1) In order to use the API, the following packages/classes
How to Verify needs to be imported:
Tooltip using Selenium WebDriver
(/images/2-
2017/072717_0606_VerifyToolt1.png)
Step 2) Create an object of "Actions" class and build the Sequence of user actions. Actions
class is used to build the sequence of user actions like moveToElement(), dragAndDrop()
etc. Various methods related to user actions are provided by API.
(/images/2-2017/072717_0606_VerifyToolt2.png)
Step 3) Create an Action Object using the build() method of "Actions" class. Call the
perform() method to execute all the actions built by the Actions object(builder here).
(/images/2-2017/072717_0606_VerifyToolt3.png)
We have seen how to use some of the user Actions methods provided by the API -
clickAndHold(element), moveByOffset(10,0), release(). The API provides many such
methods.
https://www.guru99.com/verify-tooltip-selenium-webdriver.html 2/10
Refer to the link (https://seleniumhq.github.io/selenium/docs/api/java/index.html?
12/13/2018 How to Verify Tooltip using Selenium WebDriver
We will try to verify the tooltip of the "github" icon at the top right of the page.
(/images/2-
2017/072717_0606_VerifyToolt4.png)
In order to do it, we will first find the element and get its 'title' attribute and verify with the
expected tool tip text.
Since, we are assuming the tool tip is in the "title" attribute, we are not even automating the
mouse hover effect but simply retrieving the attribute's value using the "getAttribute()"
method.
(/images/2-2017/072717_0606_VerifyToolt5.png)
https://www.guru99.com/verify-tooltip-selenium-webdriver.html 3/10
12/13/2018 How to Verify Tooltip using Selenium WebDriver
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.*;
System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
if(actualTooltip.equals(expectedTooltip)) {
Explanation of code
Some plugins expect the tooltip HTML to be present all the time next to the element for
which the tooltip is applicable whereas the others create a dynamic "div" tag, which appears
on the fly while hovering over the element.
https://www.guru99.com/verify-tooltip-selenium-webdriver.html 4/10
For our
12/13/2018 demonstration, let's consider the "jQuery
How to Tools
Verify Tooltip Tooltip"
using Selenium way of tooltip implementation.
WebDriver
(/images/2-2017/072717_0606_VerifyToolt6.png)
If you look at the source below, you can see that the div tag representing the tooltip is always
present next to the "Download now" link's tag. But, the code inside the script tag below
controls when it needs to popup.
(/images/2-2017/072717_0606_VerifyToolt7.png)
Let's try to verify just the link text in the tooltip for our demonstration here.
We will first find the WebElement corresponding to the "Download now". Then using the
Interactions API, we will move to the element (mouse-hover). Next, we will find the
WebElement that corresponds to the link inside the displayed tooltip and verify it against the
expected text.
https://www.guru99.com/verify-tooltip-selenium-webdriver.html 5/10
12/13/2018 How to Verify Tooltip using Selenium WebDriver
(/images/2-2017/072717_0606_VerifyToolt8.png)
https://www.guru99.com/verify-tooltip-selenium-webdriver.html 6/10
12/13/2018 How to Verify Tooltip using Selenium WebDriver
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.*;
System.setProperty("webdriver.chrome.driver","G:\\chromedriver.exe");
builder.clickAndHold().moveToElement(download);
builder.moveToElement(download).build().perform();
if(actualTooltip.equals(expectedTooltip)) {
Code Explanation
1. Find the WebElement that corresponds to the element "download now" that we will
mouse-hover.
2. Using the Interactions API, mouse hover on to the "Download now".
3. Assuming the tooltip is displayed, find the WebElement that corresponds to the link inside
the tooltip i.e. the "a" tag.
4. Verify the link's tooltip text retrieved using the getText() against an expected value we
have stored in "expectedToolTip"
https://www.guru99.com/verify-tooltip-selenium-webdriver.html 7/10
Summary:
12/13/2018 How to Verify Tooltip using Selenium WebDriver
In this tutorial, you have learnt how to access Tooltips using Selenium Web driver.
Next (/flash-testing-selenium.html)
Selenium Tutorials
42) SSL Certificate Error Handling (/ssl-certificate-error-handling-selenium.html)
https://www.guru99.com/verify-tooltip-selenium-webdriver.html 9/10
12/13/2018 How to Verify Tooltip using Selenium WebDriver
(https://www.facebook.com/guru99com/)
(https://twitter.com/guru99com)
(https://www.youtube.com/channel/UC19i1XD6k88KqHlET8atqFQ)
(https://forms.aweber.com/form/46/724807646.htm)
About
About US (/about-us.html)
Advertise with Us (/advertise-us.html)
Write For Us (/become-an-instructor.html)
Contact US (/contact-us.html)
Career Sugges on
SAP Career Suggestion Tool (/best-sap-module.html)
Software Testing as a Career (/software-testing-career-
complete-guide.html)
Certificates (/certificate-it-professional.html)
Interes ng
Books to Read! (/books.html)
Suggest a Tutorial
Blog (/blog/)
Quiz (/tests.html)
Review (/best-ergonomic-mouse.html)
Execute online
Execute Java Online (/try-java-editor.html)
Execute Javascript (/execute-javascript-online.html)
Execute HTML (/execute-html-online.html)
Execute Python (/execute-python-online.html)
https://www.guru99.com/verify-tooltip-selenium-webdriver.html 10/10