 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
How to 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
 