
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Tooltip Text in Selenium WebDriver
We can get the tooltip text in Selenium webdriver with help of the method - getAttribute. The attribute title should be passed as a parameter to this method.
This technique is only applicable if the element has a title attribute.
The tooltip text is the one which gets displayed on hovering the mouse over the element. In the below html code, an element having a tooltip has the attribute title and the value set for title is actually the tooltip text.
The below image shows the menu Coding Ground showing the tooltip text as - Coding Ground - Free Online IDE and Terminal.
Syntax
WebElement m = driver.findElement(By.linkText("Coding Ground")); String s = m.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 ToolTipTxt{ 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("Coding Ground")); // get title attribute value String t = l.getAttribute("title"); System.out.println("Retrieved tooltip text as :" +t); driver.quit(); } }
Output
Advertisements