tags:

views:

75

answers:

4

Given the following HTML code (which, I realise, sucks, but that's not something I can currently solve):

<img height="64" width="64" class='list_item' src="/img/icon/first.jpg" 
title="This is the first item::Completed the item "I did this first"" alt="First" />

gives me a result of (this is an image.to_s)

name:
type:
id:
value:
disabled:
src:          /img/icon/first.jpg
width:        64
height:       64
alt:          First

Note lack of "title" element. This does not actually change (the lack of the title element)

If I get the contents of the parent div of one of those icons, I get something like:

<img class="list_item" I="" did="" this="" first="" src="/img/icon/first.jpg" alt="First">

The broken HTML of the original has been turned into separate attributes somewhere down the line, but the title tag appears to have been stripped completely, and since it's the contents of the title tag I need, I'm a little stuck.

This has been tried with lastest Watir on Ruby 1.9.2 using Firefox.

Perfect world solution: I'd like to get the original transmitted HTML for the image tag, so I can "special case" (ie, hack) around the stupid double-quote problem.

Good Enough Solution: the contents of the title tag.

A: 

getting the title probably isn't working because the way the title attribute is set on that element isn't valid. entities " and < and > need to be escaped inside html attributes, with " and < and > respectively. Escape the quotes and try again.

Ethan
As I say twice in the original question, the HTML code is not mine, and I know that it sucks. However, it does contain *a* valid title tag, and some invalid attributes (because the second quote should end the title attribute and the rest is garbage), as I said, that will do.
Aquarion
A: 

dang, that didn't work. trying again:

" should be replaced with &quot;

< should be replaced with &lt;

should be replaced with &gt;

Ethan
Ethan, you can edit your answers. You should delete this one and edit the original.
Željko Filipin
A: 

Not sure, but I don't think Watir supports image titles. I looked over the Supported Elements page, title was x'ed out. I don't see it in the RDoc for Watir::Image type either.

Dave McNulla
+2  A: 

There is actually a #title method on Watir::Image. With the above incorrect HTML the output would be like this (where 'i' is the Image object):

i.title
=> "This is the first item::Completed the item "

This shows only part of the title.

But you could use #html and then parse all the necessary information out of it with some magic:

i.html
=> "<IMG class=list_item title=\"This is the first item::Completed the item \" alt=First src=\"/img/icon/first.jpg\" width=64 height=64 first?? this did I>"

But as other answers above have mentioned - you cannot get it out correctly due to the bad HTML. Maybe there's some other way to accomplish your bigger goal you're having?

Jarmo Pertman
It appears to work in the minimal test case, but not in the full application, which means there's a bug somewhere else. Ah well. Thanks :)
Aquarion
Turns out there was some javascript removing the title attributes because they thought the popups were "ugly".
Aquarion