views:

61

answers:

3

I wan to check whole site's <img> image's for alt text. I want to get a report of, What is written in alt text or alt is defined or not from all images being used on whole site in every page.

Is it possible to get report like this? after getting report i will put alt or if alt is already added but blank, then will write description text.

Otherwise in a big site it will take huge time to go and check each page.

Site is on Intranet and accessible with username and password.

A: 

This isn't a direct answer, but since it seems like your motivation here is just to know which img elements don't have alt attributes, I wanted to add that not all img elements need alt attributes.

The HTML5 spec mentions which img elements should have alt attributes:

What an img element represents depends on the src attribute and the alt attribute.

If the src attribute is set and the alt attribute is set to the empty string

  • The image is either decorative or supplemental to the rest of the content, redundant with some other information in the document.
  • If the image is available and the user agent is configured to display that image, then the element represents the image specified by the src attribute.
  • Otherwise, the element represents nothing, and may be omitted completely from the rendering. User agents may provide the user with a notification that an image is present but has been omitted from the rendering.

If the src attribute is set and the alt attribute is set to a value that isn't empty

  • The image is a key part of the content; the alt attribute gives a textual equivalent or replacement for the image.
  • If the image is available and the user agent is configured to display that image, then the element represents the image specified by the src attribute.
  • Otherwise, the element represents the text given by the alt attribute. User agents may provide the user with a notification that an image is present but has been omitted from the rendering.

If the src attribute is set and the alt attribute is not

  • The image might be a key part of the content, and there is no textual equivalent of the image available.
  • Note: In a conforming document, the absence of the alt attribute indicates that the image is a key part of the content but that a textual replacement for the image was not available when the image was generated.
  • If the image is available, the element represents the image specified by the src attribute.

If the src attribute is not set and either the alt attribute is set to the empty string or the alt attribute is not set at all

  • The element represents nothing.

Otherwise

  • The element represents the text given by the alt attribute.
HaleFx
A: 

If you wanted to do this with Selenium it will be something like this

Dictionary<string,string> details = new Dictionary<string,string>();
int imgcount = selenium.GetXpathCount("//img");
for (i=0;i<10;i++){
  details.add(selenium.GetAttribute("//img[i]@src"),selenium.GetAttribute("//img[i]@alt"));
}

foreach (KeyValuePair<string, string> kvp in details)
{
   Console.WriteLine("key " + kvp.Key);
   Console.WriteLine("Value " + kvp.Value);
}

That will print the src of the image and its ALT text.

AutomatedTester
thnaks for answer. How to run this script on whole site using Selenium in Firefox?
metal-gear-solid
A: 

Using TestPlan I came up with this quick script:

GotoURL http://stackoverflow.com/questions/2570421/how-to-generate-a-report-for-particular-xhtml-tag-attributes

foreach %Image% in (response //img)
    set %src% as combineCurrentURL (selectIn %Image% @src)
    set %alt% as trim (selectIn %Image% @alt)

    if numComp 0 = (length %alt%)
        Notice %src% ALT IS EMPTY
    else
        Notice %src% : %alt%
    end
end

The output looks like below (a CSV report can also be generated if desired)

00000001-00 NOTICE http://sstatic.net/so/img/logo.png : Stack Overflow
00000002-00 NOTICE http://ads.stackoverflow.com/ads/ladywhobig.jpg ALT IS EMPTY
00000003-00 NOTICE http://sstatic.net/so/img/vote-arrow-up.png : vote up
00000004-00 NOTICE http://sstatic.net/so/img/vote-arrow-down.png : vote down

This works in both the HTMLUnit and Selenium backend to TestPlan.

edA-qa mort-ora-y