How can I capture Tooltip in Selenium WebDriver?

How can I capture Tooltip in Selenium WebDriver?

Hi Brett,

The following test script allows you to capture the tooltip on Gmail webPage using Selenium WebDriver:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;

public class TooltipGmail {

  public static void main(String[] args) {

    WebDriver driver=new FirefoxDriver();
    driver.manage().window().maximize();
    driver.get("https://accounts.google.com/SignUp?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ltmpl=default");

    driver.findElement(By.xpath(".//*[@id='GmailAddress']")).click();
    WebElement username_tooltip=driver.findElement(By.xpath("html/body/div[2]/div[1]"));

    Actions builder=new Actions(driver);
    builder.moveToElement(username_tooltip).perform();

    String tooltip_msg=username_tooltip.getText();

    System.out.println("Tooltip/ Help message is "+tooltip_msg);

 }
}