Selenium Tutorial for Beginners

How to verify tooltip text with selenium Webdriver using Java

Continuing on our Selenium Beginner’s series, let’s see how to verify Tooltip text with Selenium Webdriver using Java.

Verify Tooltip text with Selenium Webdriver using Java

What is Tooltip?

The tooltip or info tip or a hint is a common graphical user interface element. It is used in conjunction with a cursor, usually a pointer. The user hovers the pointer over an item, without clicking it, and a tooltip may appear—a small “hover box” with information about the item being hovered over.

For this article, we will look into two different type of Tool-tip – simple HTML and JQuery.

Verify Tooltip text with Selenium Webdriver using Java

To verify tooltip text with selenium Webdriver using Java, we use the getAttribute() [for HTML] OR getText() [for jQuery] methods after identifying the element on which to mouse-hover. Once you get the tooltip text, we can use the Selenium TestNG Assert function to verify the same with the expected value. In this article, we are just getting the tooltip text & printing the same in console.

Selenium HQ [HTML] | getAttribute()

What better URL than the Selenium official website to get the tooltip text in case of HTML.

SeleniumHQ Header

Browser Automation

Here when we mouse hover on the header, it has anchor tag with title attribute which is displayed as tooltip. For HTML, it is very simple to get the tooltip text by using the getAttribute() method.

jqueryui [jQuery] | getText()

For jQuery tooltip, we will open the jqueryui URL. Here when user mouse hover on the text field, the tooltip is displayed. But if you observe the HTML >> whenever user mouse hover, it will generate a div tag in which tool tip text resides. I.e. here getAttribute() won’t work!

jqueryui tooltip

 

We ask for your age only for statistical purposes.

 

To get the tool tip text here, we need to take the help of Selenium actions class.

The Code

The steps followed are,

  1. Open Chrome browser
  2. Open the website URL [Selenium HQ] & maximize the window
  3. Find the Header element
  4. Get tool-tip text & print it in console
  5. Navigate to jqueryui website URL
  6. Navigate to Frame where text-box is present
  7. Find the Text box element using id
  8. Using Action class to mouse hover on Text-box & then identifying the tool-tip element
  9. Get tool-tip text & print it in console

The Result | Tooltip text

Following is the result of executing above code,

We hope this article gives you a basic understanding of how to verify tooltip text with selenium Webdriver using Java.

Leave a Reply

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