- 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 capture tooltip in Selenium using getAttribute?
We can capture the tooltip in Selenium using the getAttribute method.
This technique can only be used for an element which has the attribute in its html code.
A tooltip text becomes visible from an element as we hover the mouse on it. To obtain the tooltip we have to pass the title as a parameter to the getAttribute method.
Let us see the html code of an element UFSC Notes having a tooltip.
Here, the tooltip text displayed from UPSC Notes is UPSC IAS Exams Notes -
TutorialsPoint which is the value set for the title attribute.
Syntax
WebElement l = driver.findElement(By.linkText("UPSC Notes")); String a = l.getAttribute("title");
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 TooltipAttribute{ 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 l = driver.findElement(By.linkText("UPSC Notes")); //get title attribute String a = l.getAttribute("title"); System.out.println("Tooltip obtained from title: " + a); driver.quit(); } }
Output
- Related Articles
- How to capture tooltip in Selenium using Actions Class?
- How to Verify Tooltip using Selenium WebDriver?
- How to capture screenshots in Selenium?
- How to get Tooltip Text in Selenium Webdriver?
- Difference b/w getText() and getAttribute() in Selenium WebDriver
- How can I capture network traffic of a specific page using Selenium?
- How to capture the text from Alert Message in Selenium Webdriver?
- How to capture the screenshot of a specific element rather than entire page using Selenium Webdriver?
- How to Create Link Tooltip Using CSS3 and jQuery?
- How to add a tooltip to a div using JavaScript?
- How to capture video from default camera in OpenCV using C++?
- How to capture video from other cameras in OpenCV using C++?
- Building Tooltip using CSS
- How to capture SIGINT in Python?
- How to display a variable as tooltip in ggplotly using R language?

Advertisements