Showing posts with label Tooltip. Show all posts
Showing posts with label Tooltip. Show all posts

Sunday, May 11, 2014

How to get the tooltip for all the images present in the webpage.

Note- code has been done in such a way so that it will not print those title which are blank.


import java.util.List;
import java.util.concurrent.TimeUnit;

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

public class Deepika {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://www.swissoutpost.com/");
        List<WebElement> imgs = driver.findElements(By.tagName("img"));
        System.out.println(imgs.size());
        int num =0;
        String toolTip="";
        for(int i=0; i<imgs.size(); i++){
            toolTip = imgs.get(i).getAttribute("title");
            num+=1;
            if(toolTip.equals("")){
            }else{
                System.out.println(toolTip);
            }
        }
        System.out.println(num);
    }
}