- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to Verify Tooltip using Selenium WebDriver?
We can verify the tooltip of an element using Selenium webdriver using the getAttribute method. A tooltip text is the one which gets displayed while we hover on that element.
It disappears once we move the mouse away from the element. A tooltip text generally displays the title attribute value of an element. First, we identify the element then apply the getAttribute method on it. The parameter to be passed to this method is title.
Let us investigate the html code of an element - Tools having a tooltip text.
Here, the tooltip text displayed from Tools menu is Tools - Online Development and Testing Tools which is the value set for the title attribute in the html.
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import java.util.concurrent.TimeUnit; public class TooltipVerfy{ public static void main(String[] args) { System.setProperty("webdriver.gecko.driver", "C:\Users\ghs6kor\Desktop\Java\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); //implicit wait driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //URL launch driver.get("https://www.tutorialspoint.com/index.htm"); //identify element WebElement n = driver.findElement(By.linkText("Tools")); //obtain title attribute String s = n.getAttribute("title"); //verify tooltip text if(s.equals("Tools - Online Development and Testing Tools")) { System.out.println("Tooltip text matched"); }else{ System.out.println("Tooltip text not matched"); } driver.quit(); } }
Output
- Related Articles
- How to get Tooltip Text in Selenium Webdriver?
- How to verify an attribute is present in an element using Selenium WebDriver?
- How can I verify Error Message on a webpage using Selenium Webdriver?
- How to capture tooltip in Selenium using getAttribute?
- How to verify color of a web element in Selenium Webdriver?
- How to capture tooltip in Selenium using Actions Class?
- How to upload files using Selenium Webdriver?
- How to select checkboxes using selenium java webdriver?
- How to deal with ModalDialog using selenium webdriver?
- How to click on across browsers using Selenium Webdriver?
- How to handle frame in Selenium WebDriver using java?
- How to handle windows file upload using Selenium WebDriver?
- How to check URL for 404 using Selenium WebDriver?
- How to scroll down using Selenium WebDriver with Java?
- How to get HTTP Response Code using Selenium WebDriver?

Advertisements