Verifying ToolTip information by enabling javascript in browser

01 April, 2014
Most of the websites now use the ToolTip to provide more information to the user.

ToolTip also known as ScreenTip is visible to the user whenever they mouseover on specific object. It just displays information about the object(button,textbox,link,image etc.).

ToolTips work only when javascript is enabled. Automating ToolTip involves:
  • Verifying that tooltip presents when we mouseover on specific object
  • Verifying the text that is presented by the tooltip.

In this website if we mouseover on the "Download" link we will see a tooltip.

In this sample program we will check the existence of tooltip and also the text present in the tooltip. We will use the HtmlDriver because it provides inbuilt methods for enabling and disabling of javascript.

import org.openqa.selenium.By;  
import org.openqa.selenium.WebElement;  
import org.openqa.selenium.htmlunit.HtmlUnitDriver;  
import org.openqa.selenium.interactions.Action;  
import org.openqa.selenium.interactions.Actions;  
public class HTMLdriver {  
 public static void main(String args[]){  
   HtmlUnitDriver driver = new HtmlUnitDriver();  
   WebElement element=driver.findElement(By.linkText("Download"));  
   Actions builder = new Actions(driver); 
   Action mouseOver =builder.moveToElement(element).build();     
      System.out.println("Tooltip is presented");  
      System.out.println("The tool tip text is: "+driver.findElement("tooltip")).getText());  
      System.out.println("Tool tip text does not exist");  

To check the correctness of the program, disable javascript and run the program. The script will fail as tooltip fails to appear when we mouseover on Download link.


No comments:

Post a Comment