Skip to main content

How to Handle Tooltips using selenium Webdriver.

Handling the tooltips are easy in selenium, we can achieve by using getAttribute("title"). where tooltips value is given in title attribute. 

Do check out below code for implementation:

 

package SeleniumBasics;

import org.openqa.selenium.By;

import org.openqa.selenium.JavascriptExecutor;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.interactions.Actions;


public class Seleniumtooltips {

    public static void main(String[] args) {

System.setProperty("webdriver.chrome.driver", "E:\\eclipseprojects\\seleniumDemo\\server\\chromedriver.exe");

WebDriver driver = new ChromeDriver();

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

driver.get("https://www.facebook.com/");

WebElement link1 = driver.findElement(By.linkText("Sign Up"));

JavascriptExecutor scroll = (JavascriptExecutor) driver;

scroll.executeScript("window.scrollBy(0,1000)");

try {

Thread.sleep(1000);

} catch (Exception e) {

// TODO: handle exception

e.printStackTrace();

}

Actions action = new Actions(driver);

action.moveToElement(link1).perform();

String tooltip = link1.getAttribute("title");

System.out.println("verifying the tooltip :" + tooltip);

}

}

 

Watch out Video in YouTube : 





Comments