TestComplete Web Testing Quick Tip: Checking ALT attributes of IMG Tags

TestComplete provides scripting access to web page elements as well as to methods, properties and events of elements. Using this functionality, you can check different characteristics of a web page and its elements. For example, you can check whether the ALT attribute is specified for all images on the page. Why is this attribute so important?

  • The attribute is needed so that people who have low vision could work with the page.
  • The text of the ALT attribute is used by text browsers for indicating an image.
  • The text of the attribute is used by regular browsers and if the image indication option is disabled in browser settings.
  • ALT is used by search engines for page indexing.

Microsoft recommends that the ALT attribute be used to create accessible web pages. In some companies using this attribute is also required by internal standards for documentation and web pages. Many authors (for instance, http://www.xs4all.nl/~sbpoley/webmatters/checklist.html#access) suggest including the check for ALT tags into a web page checklist.

Since TestComplete provides access to web page elements, you can easily check whether the ALT attribute is used for images on the tested pages. The following code demonstrates how you can do this:

  • venkata

    I have a problem while IEFrame method, which is not working for browser firefox and chrome, could you please help me like other alternative method instead of IEFrame for firefox. 
     
     
     
    var oIEFrame = Page.Window(“IEFrame”, “*”); 
     
     
     
    Note: The above code is working for IE Browser but I need it for firefox please help me

  • Allen

    Hi, 
     
    Here’s a script which works with Firefox: 
     
    function Test() 

    CheckALTAttrs(Browsers.btFirefox, “http://www.google.com”); 

     
    function CheckALTAttrs(BrowserType, URL) 

    var 
    i, 
    w1, 
    Images, 
    Page; 
    var Browser = Browsers.Item(BrowserType); 
    Browser.Run(); 
    Browser.Navigate(URL); 
    Page = Aliases.Browser.Page(“http://www.google.com/”); 
    if (Options.Web.TreeModel == “DOM”) 
    Images = Page.document.images; 
    else 
    Images = Page.contentDocument.images; 
    for (i = 0; i < Images.length; i++) 
    if (Images.item(i).alt == “”) 

    CheckResult = false; 
    Log.Error(“The “alt” property of the document.images.item(” + VarToStr(i) + “) object is empty. “, “outerHTML: ” + Images.item(i).outerHTML); 


     
    – 
    Best regards, 
    Allen