This thread may help. Regards https://groups.google.com/forum/#!searchin/watir-general/Any$20fast$20ways$20to$20parse$20a$20table%7Csort:relevance/watir-general/jk58Xf0DomE/Vdwwz2pYndQJ
On Friday, June 6, 2014 3:21:18 PM UTC-5, Joe Fl wrote: > > Hi Everyone, > > I am putting a test together to confirm the correct data is displaying > within a UI table. I found here that someone suggested using Nokogiri with > watir webdriver and tried it out but i do not really understand what it is > doing. > > Related Article: > https://groups.google.com/forum/#!searchin/watir-general/table/watir-general/jk58Xf0DomE/Vdwwz2pYndQJ > > First I get data through a URI search from elastic search using > rest-client. > > data_to_validate = get_grid_data(request_caller_state('ID')) > => {"Call Date"=>"2014-05-21 12:33:07", > "Call Campaign"=>"pizza 1:1", > "Transcription"=>"Processed", > "Incoming #"=>"4442416734", > "Tracking #"=>"4444731333", > "Destination #"=>"4449206417", > "Rings"=>5, > "Duration"=>"184", > "Call Disposition"=>"ANSWER", > "Keywords"=>"", > "Keyword Type"=>"", > "Recording"=> > " > http://recordings.mongoosemetrics.com/unprocessed/e3fc47393f90720fc0fb6573fff5a541.wav > ", > "State"=>"ID", > "City"=>"POCATE", > "Zip"=>"11122"} > > *UI Table* > table_obj = @browser.table(:class=>'table table-striped table-bordered > table-hover table-condensed table-checkable datatable').tbody > myArray = data_to_validate.values > check_table_vs_elastic_data(table_obj,myArray) > > def check_table_vs_elastic_data(table_obj,myArray) > nokogiri = Nokogiri::HTML.parse(table_obj.html) > nokogiri.css('tr').each_with_index do |tr, i| > if tr.css('td').collect(&:text) == myArray *<== This the part I do > not really understand. I understand the .collect(&:text) get all of the > rows data. (I think)* > puts "Row to click: #{i}" > end > end > end > > > When I run it I get all of this Nokogiri output and nothing that tells me > it worked successfully. > > Part of the output: > [#<Nokogiri::XML::Element:0x3ff2ab136f68 name="tr" > children=[#<Nokogiri::XML::Text:0x3ff2ab139e70 "\n > ">, #<Nokogiri::XML::Element:0x3ff2ab136b44 > name="td" attributes=[#<Nokogiri::XML::Attr:0x3ff2ab139cf4 name="class" > value="column-cdr_entry_date">, #<Nokogiri::XML::Attr:0x3ff2ab139ce0 > name="style" value="white-space: nowrap; display: table-cell;">] > children=[#<Nokogiri::XML::Text:0x3ff2ab13940c "\n > 2014-05-21 12:33:07 > ">]>, #<Nokogiri::XML::Text:0x3ff2ab1391dc "\n > ">, > #<Nokogiri::XML::Element:0x3ff2ab136b1c name="td" > attributes=[#<Nokogiri::XML::Attr:0x3ff2ab139038 name="class" > value="column-cdr_rated_code">, #<Nokogiri::XML::Attr:0x3ff2ab139024 > name="style" value="white-space: nowrap; display: none;">] > children=[#<Nokogiri::XML::Text:0x3ff2ab138750 "\n > e3fc47393f90720fc0fb6573fff5a541 > ">]>, #<Nokogiri::XML::Text:0x3ff2ab1384d0 "\n > ">, #<Nokogiri: > > > table html > > <table class="table table-striped table-bordered table-hover > table-condensed table-checkable datatable"> > <thead></thead> > <tbody> > <tr> > <td class="column-cdr_entry_date" style="white-space: nowrap; > display: table-cell;"> > TEXT > </td> > <td class="column-cdr_rated_code" style="white-space: nowrap; > display: none;"> > TEXT > </td> > <td class="column-campaign_name" style="white-space: nowrap; > display: table-cell;"></td> > <td class="column-campaign_code" style="white-space: nowrap; > display: none;"></td> > <td class="column-campaign_billing_type" style="white-space: > nowrap; display: none;"></td> > <td class="column-mixed" style="white-space: nowrap; display: > table-cell;"></td> > <td class="column-account_code" style="white-space: nowrap; > display: none;"></td> > <td class="column-incoming_number" style="white-space: nowrap; > display: table-cell;"></td> > <td class="column-did_number" style="white-space: nowrap; > display: table-cell;"></td> > <td class="column-destination_number" style="white-space: > nowrap; display: table-cell;"></td> > <td class="column-rings_count" style="white-space: nowrap; > display: table-cell;"></td> > <td class="column-call_duration" style="white-space: nowrap; > display: table-cell;"></td> > <td class="column-duration_in_mins" style="white-space: > nowrap; display: none;"></td> > <td class="column-message" style="white-space: nowrap; > display: table-cell;"></td> > <td class="column-promocode" style="white-space: nowrap; > display: none;"></td> > <td class="column-keywords" style="white-space: nowrap; > display: table-cell;"></td> > <td class="column-keyword_type" style="white-space: nowrap; > display: table-cell;"></td> > <td class="column-recording" style="white-space: nowrap; > display: table-cell;"></td> > <td class="column-incoming_caller_name" style="white-space: > nowrap; display: none;"></td> > <td class="column-caller_state" style="white-space: nowrap; > display: table-cell;"></td> > <td class="column-caller_city" style="white-space: nowrap; > display: table-cell;"></td> > <td class="column-caller_areacode" style="white-space: nowrap; > display: none;"></td> > <td class="column-caller_zip" style="white-space: nowrap; > display: table-cell;"></td> > <td class="column-caller_timezone" style="white-space: nowrap; > display: none;"></td> > <td class="column-route_type" style="white-space: nowrap; > display: none;"></td> > <td class="column-email" style="white-space: nowrap; display: > none;"></td> > <td class="column-custom1" style="white-space: nowrap; > display: none;"></td> > <td class="column-custom2" style="white-space: nowrap; > display: none;"></td> > <td class="column-custom3" style="white-space: nowrap; > display: none;"></td> > </tr> > </tbody> > </table> > > > Any help would be appreciated. If someone else has another suggestion > that would be great too. > I could multiple rows to validate. > > Thank you, > Joe > > > -- -- 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/d/optout.
