Watir question

hi, please have a look at the below tag

I can able to print the id of td from the above tag, but I couldn’t able
to print the styleId from the above tag, how would I do that?

b.tds.each do |t|
put t.id #this works fine
end

b.tds.each do |t|
put t.styleId #this is not working for me
end

Is there any way I could print the styleId from the above tag?

As with any custom attribute:

t.attribute_value(“styleId”)

hi Joel P.

It’s great,working fine. I got the value of styleId attribute.

hi Joel,

Do you know which class owns this methods ‘attribute_value’?

hi jeol,

For the above html code,I have written the below code,

puts
$browser.text_field(:id,‘IDITForm@firstName’).attribute_value(‘name’)
puts
$browser.text_field(:id,‘IDITForm@firstName’).attribute_value(‘tabIndex’)
puts
$browser.text_field(:id,‘IDITForm@firstName’).attribute_value(‘class’)
puts $browser.text_field(:id,‘IDITForm@firstName’).attribute_value(‘id’)
puts
$browser.text_field(:id,‘IDITForm@firstName’).attribute_value(‘style’)
puts
$browser.text_field(:id,‘IDITForm@firstName’).attribute_value(‘onfocus’)
puts
$browser.text_field(:id,‘IDITForm@firstName’).attribute_value(‘type’)

The result is,
IDITForm@firstName
308
nil
IDITForm@firstName
#WIN32OLE:0xf5d3ea0
#WIN32OLE:0xf5d37f8
text

My question is, why it prints nil for ‘class’ attribute, style and
onfocus it’s prints object name?

hi Thank you,very useful.

You can always check the documentation:
http://rdoc.info/gems/watir-webdriver/Watir/Element#attribute_value-instance_method

Your HTML doesn’t match your selector. That’s not the same element.