Getting value from value-value attribute in capybara

Hey, I'm trying to set this up so that it pulls out the value to use, this is 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 the value of the data (useage) data-series = "runtime" the end result should be: useage = 164

+5
source share
1 answer

Nodes have a [] method that returns attribute values.

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

 usage = page.find('td[data-series="runtime"]')['data-value'] p usage #=> "164" 
+10
source

Source: https://habr.com/ru/post/1200339/


All Articles