Get Tooltip Text Using Selenium WebDriver

Get Tooltip Text

Tooltip : many times we see, when we hovers mouse on button or link or text or any web page field,an information displays; is nothing but tooltip! With respect to text validation test cases ,it is must to verify whether tooltip text is displayed correctly or not.
So,Let us see how to get tooltip text using selenium webdriver.
check below image and selenium code for the same.

selenium webdriver window handling

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package scripts;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class tooltip {

public static void main(String[] args) throws InterruptedException {

//set GeckoDriver path for FireFox browser
System.setProperty("webdriver.gecko.driver", "C:\\harshal personal\\selenium\\geckodriver-v0.10.0-win64\\geckodriver.exe");

//Create Browser object
WebDriver driver = new FirefoxDriver();

//open URL
driver.get("[http://www.seleniumpoint.com/testwebsite.php](http://www.seleniumpoint.com/testwebsite.php)");

//maximize the window
driver.manage().window().maximize();

//login to test web site
driver.findElement(By.id("remail")).sendKeys("test@seleniumpoint.com ");
driver.findElement(By.id("rpassword")).sendKeys("test@123");
driver.findElement(By.id("rsubmit")).click();

Thread.sleep(3000);

//Get Tool tip text : mouse hover on product 1 name : Nikon d 50 you will see tooltip

String toolTipText = driver.findElement(By.xpath("//div[@class='product1Name']//a")).getAttribute("title").toString();
System.out.println("Tool Tip Text is :" + toolTipText);

}

}

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×