Hi!

I would suggest troubleshooting your imgs array.  Try doing a puts
imgs after the variable is created to see what is stored in it.  It
looks like the array may actually be empty, or maybe you have a
mismatch with your array index.

Hope this helps!

-Tiffany

On Apr 22, 9:25 am, thestumonkey <[email protected]> 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
>                 �[email protected]("Alt Text", 'PASS', "A:
> '#{i.alt}'<br>E: '#{altText}'")
>                  #puts "  AltText correct. Actual '#{i.alt}' expected
> is '#{altText}'"
>                 else
>                 �[email protected]("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 readhttp://watir.com/support. In short: search before 
> you ask, be nice.
>
> You received this message because you are subscribed 
> tohttp://groups.google.com/group/watir-general
> To post: [email protected]

-- 
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: [email protected]

Reply via email to