Reputation: 3920
I need to read text value from span tag inside a selected radio button using capyvara
I have a list of radio button
followed by text and its count in brackets.
For eg: radiobutton with Thank You(82)
What I want is to read the selected radio button count 82 inside bracket.
I used following code..but it is not working
value=page.find(".cardFilterItemSelection[checked='checked'] + span.itemCount").text
and tried using Xpath but not getting anything
value=page.find(:xpath,"//input[@class = 'cardFilterItemSelection' and @checked = 'checked']/span[@class = 'itemCount']/text()")
How it is possible?
<label id="thankyou_label" for="thankyou_radio" class="itemName radio">
<input checked="checked" tagtype="Occasion" value="Thank You" id="thankyou_radio" name="occasionGroup" class="cardFilterItemSelection" type="radio">
<span class="occasion_display_name">
Thank You
</span>
<span class="itemCount">
(82)
</span>
</label>
<label id="spring_label" class="itemName radio" for="spring_radio">
<input id="spring_radio" class="cardFilterItemSelection" type="radio" name="occasionGroup" value="Spring" tagtype="Occasion">
<span class="occasion_display_name">
Spring
</span>
<span class="itemCount">
(0)
</span>
</label>
Upvotes: 1
Views: 3881
Reputation: 1127
I think you were on the right track. But you should have query not for the text node contained by span, but for the span itself and use XPath axes
span = page.find(:xpath,"//input[@class = 'cardFilterItemSelection' and @checked = 'checked']/following-sibling::span[@class = 'itemCount']")
value = span.text
However I personally find css selectors more readable (unless you need to make complex query)
span = page.find(:css, 'input.cardFilterItemSelection[checked=checked] ~ span.itemCount')
value = span.text
Upvotes: 11