Dan,
Thanks so much, that worked perfectly.
-Fred
On Monday, July 1, 2013 8:59:05 AM UTC-4, Dan wrote:
>
> I think you want this.
>
> >> b.ul(:class =>
> "battery-level-list").attribute_value("data-battery-level")
> => "5.71535"
>
> On Sunday, June 30, 2013 10:01:24 AM UTC-4, Fred Cassirer wrote:
>>
>> Hi,
>>
>> I have been struggling with how to extract the value of
>> "data-battery-level" from the code below:
>>
>> <div class="battery"> <ul class="battery-level-list"
>> data-battery-level="5.71535"> <li
>> class="green">1</li> <li class="green">1</li>
>> <li class="green">1</li> <li
>> class="green">1</li> </ul> </div>
>>
>>
>> Below is a snip from my interactive debugging window
>>
>> >> b = Watir::Browser.new
>>
>> ?> d= b.div :class => 'battery'
>> => #<Watir::Div:0x101693258 located=false selector={:class=>"battery",
>> :tag_name=>"div"}>
>> >> d.text
>> => "1\n1\n1\n1"
>> >> d.exists?
>> => true
>> >> u=b.div :class => 'battery-level-list'
>> => #<Watir::Div:0x101650200 located=false
>> selector={:class=>"battery-level-list", :tag_name=>"div"}>
>> >> u.exists?
>> => false
>> >> d.text
>> => "1\n1\n1\n1"
>> >> d.ul
>> => #<Watir::UList:0x1012209f0 located=false selector={:tag_name=>"ul"}>
>> >> d.elements
>> => #<Watir::HTMLElementCollection:0x1011dd358 @selector={},
>> @parent=#<Watir::Div:0x..fe7cbadc7c located=true
>> selector={:class=>"battery", :tag_name=>"div"}>>
>> >> d.sections
>> => #<Watir::HTMLElementCollection:0x1010c9c50
>> @selector={:tag_name=>"section"}, @parent=#<Watir::Div:0x..fe7cbadc7c
>> located=true selector={:class=>"battery", :tag_name=>"div"}>>
>> >> d.sections.size
>> => 0
>> >> d.ul
>> => #<Watir::UList:0x1019c3ba8 located=false selector={:tag_name=>"ul"}>
>> >> b.ul
>> => #<Watir::UList:0x1019c0ed0 located=false selector={:tag_name=>"ul"}>
>> >> d.ul(:class,'battery-level-list')
>> => #<Watir::UList:0x1019b7b50 located=false
>> selector={:class=>"battery-level-list", :tag_name=>"ul"}>
>> >> b.ul(:class,'battery-level-list')
>> => #<Watir::UList:0x1019a1378 located=false
>> selector={:class=>"battery-level-list", :tag_name=>"ul"}>
>> >> d.attribute_value('class')
>> => "battery"
>> >> d.attribute_value('ul')
>> => nil
>> >> d.attribute_value('data-battery-level')
>> => nil
>> >> b.div(:class,"battery").text
>> => "1\n1\n1\n1"
>> >> b.div(:class,"battery").li(:index,2).text
>> => "1"
>> >> b.div(:class,"battery-level-list")
>> => #<Watir::Div:0x10175b960 located=false
>> selector={:class=>"battery-level-list", :tag_name=>"div"}>
>> >> b.div(:class,"battery").elements
>> => #<Watir::HTMLElementCollection:0x101741e20 @selector={},
>> @parent=#<Watir::Div:0x101741e70 located=false selector={:class=>"battery",
>> :tag_name=>"div"}>>
>> >> b.div(:class,"data-battery-level")
>> => #<Watir::Div:0x101736368 located=false
>> selector={:class=>"data-battery-level", :tag_name=>"div"}>
>> >> b.ul(:class,'battery')
>> => #<Watir::UList:0x10172b850 located=false selector={:class=>"battery",
>> :tag_name=>"ul"}>
>> >> b.ul(:class,'battery-level-list')
>> => #<Watir::UList:0x101720d38 located=false
>> selector={:class=>"battery-level-list", :tag_name=>"ul"}>
>>
>> As you can see, I'm not finding anything in the b. or d. objects that
>> seem to be able to list out what the data-battery-level is. I've spent
>> several hours searching all of the various forums and documentation, and
>> have not yet found any similar examples.
>>
>> Any help or insight would be greatly appreciated ... I'm trying to pull
>> this value from my wifi enabled keypad doorkock page so I can create an
>> alert when the battery goes low (unfortunately, the web site doesn't
>> provide this function), it goes from working to out of juice with no
>> warning and it's not fun getting locked out of the house ;-)
>>
>> Thanks again.
>>
>
--
--
Before posting, please read http://watir.com/support. In short: search before
you ask, be nice.
[email protected]
http://groups.google.com/group/watir-general
[email protected]
---
You received this message because you are subscribed to the Google Groups
"Watir General" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.