[Watir-webdriver] : How to retrieve/print text from a table

174 views
Skip to first unread message

watir webdriver

unread,
Aug 14, 2013, 10:56:22 AM8/14/13
to watir-...@googlegroups.com
Is there any way how to print the text from the table?
I've managed to verify if the text is present on the page or not but not sure how to print the text.Its a table with 20 rows.


Then(/^I should see "(.*?)" on the page$/) do |expected_result|
puts (@browser.text.include? expected_result).should == true
puts @browser.td(:text => expected_result)  ###Here I want to print the expected_result which is nothing but best
end


Sample HTML :
<tr>
<th>Generation</th>
<td>best</td>
</tr>

Any suggestions ?
Thanks in-advance...

watir webdriver

unread,
Aug 15, 2013, 7:28:00 AM8/15/13
to watir-...@googlegroups.com
Any suggestions plz....

Tadeu Panato

unread,
Aug 15, 2013, 8:25:09 AM8/15/13
to watir-...@googlegroups.com
just simple print the word best or anything in the cell? man its simple, you aleredy use that

example
<body>
<table>
  <tr>
    <td>blabla 1</td>
    <td>xoxoxo 2</td>
  </tr>
  <tr>
    <td>blblablalba 3</td>
    <td>yommamma 4</td>
  </tr>
</table>
</body>

irb:

table = b.table
#you can use searching the :text but i prefer use the index
puts t.td(:text => "blabla 1").text #should print "blabla 1"

puts t.td(:index => 3).text #should print "yommamma 4"

watir webdriver

unread,
Aug 15, 2013, 9:45:00 AM8/15/13
to watir-...@googlegroups.com
Thanks a lot Panato...


--
--
Before posting, please read http://watir.com/support. In short: search before you ask, be nice.
 
watir-...@googlegroups.com
http://groups.google.com/group/watir-general
watir-genera...@googlegroups.com
 
---
You received this message because you are subscribed to a topic in the Google Groups "Watir General" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/watir-general/R21_TCY5aeg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to watir-genera...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Oscar Rieken

unread,
Aug 15, 2013, 10:32:20 AM8/15/13
to watir-...@googlegroups.com
I personally would go and as the devs to put in some id's or I would go add them myself. because I think that checking to make sure you see text by locating the element by that same text doesnt make a whole lot of sense to me. if it fails its going to throw an element not found


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 watir-genera...@googlegroups.com.

Tadeu Panato

unread,
Aug 15, 2013, 10:45:48 AM8/15/13
to watir-...@googlegroups.com
I agree, but this is just a simple example. in real life app it should have id or class or something else.... :)
Reply all
Reply to author
Forward
0 new messages