Hi
Try this

Browser.show_images

Regards,
Mrunal





Paul Rogers wrote:
browser.images.each do |img|
  puts img.alt
end

should do it I think

On Thu, Apr 22, 2010 at 9:25 AM, thestumonkey <thestumon...@gmail.com <mailto:thestumon...@gmail.com>> wrote:

    I am using getElementsByTagName in order to get a list of images on
    the page, and then checking the alt text against that in an excel
    spreadsheet.

    This works, unless there is only 1 img on the page, in which case I
    get the error "undefined local variable or method `i' for #<Object:
    0x30f9e4>"
    I assume that this is because getElementsByTagName isn't returning an
    array that I can use the "each" method ?

    Any ideas how to solve this?


    Here is the code:

    def checkIMG(browser, record)
     imgLocation = @site + record['Image Location']
     altText = record['Alt Text']
     locationFound = 0

     imgs=
    browser.document.body.parentElement.getElementsByTagName("img")

       imgs.each do |i|
                 if i.src == imgLocation
                   @html.addtoReport("Location", 'PASS', "A:
    '#{i.src}'<br>E: '#{imgLocation}'")
                   #puts "  Location correct. Actual '#{i.src}'  expected
    is '#{imgLocation}'"
                   locationFound = 1
                   if i.alt == altText
                    @html.addtoReport("Alt Text", 'PASS', "A:
    '#{i.alt}'<br>E: '#{altText}'")
                    #puts "  AltText correct. Actual '#{i.alt}' expected
    is '#{altText}'"
                   else
                    @html.addtoReport("Alt Text", 'FAIL', "A:
    '#{i.alt}'<br>E: '#{altText}'")
                   puts "  IMG ERROR              '#{imgLocation}'"
                   puts "  ALT ERROR Actual     '#{i.alt}'"
                   puts "  ALT ERROR Expected '#{altText}'"
                   end
                 end

       end

    --
    Before posting, please read http://watir.com/support. In short:
    search before you ask, be nice.

    You received this message because you are subscribed to
    http://groups.google.com/group/watir-general
    To post: watir-general@googlegroups.com
    <mailto:watir-general@googlegroups.com>


--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice. You received this message because you are subscribed to http://groups.google.com/group/watir-general
To post: watir-general@googlegroups.com

--
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

You received this message because you are subscribed to 
http://groups.google.com/group/watir-general
To post: watir-general@googlegroups.com

Reply via email to