ToolTip in Selenium:


  • Tooltips are displayed when you roll on an icon with the cursor.
  • Tooltips are displayed automatically when users hover the pointer over an object, and are removed when users click on control or move the mouse, or when tip times out.
  • The tooltip is a text that appears when a mouse hovers over an object like a link, an image, a button, text area, etc. in a web page.


Scenario’s to Handle Tooltip in Selenium:

  • Create Instance / Object of Action Class to perform moveToElement operation.
  • findElement and store into WebElement.
  • Using Action Class Move to Element to Handle ToolTip using moveToElement Method.
  • GetText of WebElement using getText() Method and Store into String.
  • Print ToolTip string.


Step’s to Handle ToolTip in Selenium using Action Class:

  • setProperty to Launch geckodriver (Firefox).
  • Create driver Instance / Object of WebDriver.
  • Using get() Method open URL.
  • Create Action Class Object to Handle moveToElement.
  • findElement and Store into WebElement.
  • Perform moveToElement() Method to handle Hover ToolTip.
  • GetText of ToolTip and Store into String and Print.


Example of Get ToolTip Using Actions class: 


Handle ToolTip using getAttribute():

  • Selenium WebDriver has a predefined method getAttribute(“value”) that receives the value within text field, text field and any other field field including text, and assigns the retrieved title.
  • Get the value of the attribute given to the element will return the current value, even if the page has been modified after it has been loaded.
  • More accurate, this method will return the value of the given feature, in that case return the value of the property with the same name (for example “value” for a textarea element) goes.


Example of Get Tooltip using getAttribute:

How to Verify Tooltip using Selenium WebDriver and How To Get Tooltip Text In Selenium WebDriver and How to get a tooltip text on mouseover using Selenium WebDriver