Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting value from data-value attribute in capybara

Hey I'm trying to set this up so that it will pull out the value for useage, heres the code.

<tr class="data-point">
<th class="x-value" data-value="1391212800" data-label="Feb" data-description="February 2014"> February 2014 </th>
<td class="y-value" data-value="164" data-tooltip-name="usage" data-tooltip-index="2" data-series="runtime" data-description="164 hours"> 164 hours </td>
<td class="y-value" data-value="16.0" data-tooltip-name="usage" data-tooltip-index="1" data-series="savings" data-description="16 hours"> 16 hours </td>
</tr>

So I need to extract and set to a variable(useage) data-series="runtime"'s data-value end result should be: useage = 164

like image 685
Dom Avatar asked Aug 14 '14 15:08

Dom


1 Answers

Nodes have a [] method that returns attribute values.

The following shows using the method to get the data-value attribute:

usage = page.find('td[data-series="runtime"]')['data-value']
p usage
#=> "164"
like image 166
Justin Ko Avatar answered Oct 22 '22 11:10

Justin Ko