Although it won't capture the HTML tags, you can dump the contents of
a table like this:

table_contents = browser.table(:id, 'foo').to_a

For writing to .txt file, check out the ruby File class:
http://www.ruby-doc.org/core-1.9.3/File.html

This is an example for writing the HTML for a page to a file:

browser.goto(test_site)
html = browser.html

f = File.new("txt.txt", "w+")
f.write(html)
f.close

Hope it helps.

orde

On Dec 2, 1:42 am, Mark Ballinger <mark.j.ballin...@gmail.com> wrote:
> Thank you for your reply.
> After re-reading what I have written and thinking about what I what to
> achieve... I don't believe I want to extract the table data into
> excel. I would like to extract it to a .txt (notepad document).
> The purpose of extracting the data is to check it against it against
> what I have in my database :-). If I can get it into .txt file
> (notepad document) I have the know-how to clean it and import it into
> sql for validation.
> FYI the data in the table looks like this...
> <table border="1" cellpadding="2"><tr><th> Address </th><th> Council
> tax band </th><th> Annual council tax </th></tr>
> <tr><td> 2, STONELEIGH AVENUE, COVENTRY, CV5 6BZ </td><td
> align="center"> F </td><td align="center"> &pound;2125 </td></tr>
> ....... The above row is repeated many time ......
> </table>
> Then the table is closed.
> So to re-cap my situation. I can use Watir to navigate the browser to
> the page containing the html table but my problem is that I am unsure
> of how to extract the results (everything within the <table> tag -
> including the html) to a .txt file and then save that .txt file onto
> my computer.
> I would prefer to take smaller steps with using Watir. I am knew to it
> therefore I would just like to learn how to extract the table and save
> everything that I have extracted into a .txt file. I have seen a
> couple of examples online using hpricot. However most of the examples
> seem to miss off code detailing how the array (if that is the correct
> approach) is outputted into a .txt file.
> Could you help by demonstrating how to write a simple piece of code
> which will extract the html table ( and everything, including the
> <tr>, <td> and everything in between) to a .txt notepad file?
> Many thanks for your time.
> On Dec 2, 2:36 am, bis <bis...@gmail.com> wrote:
>
>
>
>
>
>
>
> > To me that sounds like a lot of extra work what happens once it is in an 
> > excel? Why would putting it in an excel be better than asserting it all 
> > within the test itself
>
> > So I'll go ahead and ask some questions first.
> > Will it happen more than once validating the excel?
> > What sort of data is in the table?
> > Would you be comparing the data in the excel vs data in a data base? If 
> > yes, why not let the test do it?
>
> > Sent from my iPhone
>
> > On Dec 1, 2011, at 4:43 PM, Mark Ballinger <mark.j.ballin...@gmail.com> 
> > wrote:
>
> > > Hi I am a newbie to groups and to ruby, watir, watir-webdriver etc...
>
> > > Basically all I would like to do is export a table from a web page
> > > which I have instructed the browser to find using Watir-webdriver. I
> > > just want to take the whole contents of the html table and place it
> > > into Excel for further analysis.
>
> > > I have the got the following code to work:
>
> > > require 'rubygems'
> > > require 'hpricot'
> > > require "watir-webdriver"
> > > url = "http://www.mycounciltax.org.uk/results?
> > > postcode=cv35+8au&search=Search"
> > > browser = Watir::Browser.new
> > > browser.goto url
>
> > > All i would like to do now is save the table. How do save the html to
> > > a csv or .txt file into my C;\Temp folder?
>
> > > Best Regards,
>
> > > Mark
>
> > > --
> > > Before posting, please readhttp://watir.com/support. In short: search 
> > > before you ask, be nice.
>
> > > watir-general@googlegroups.com
> > >http://groups.google.com/group/watir-general
> > > watir-general+unsubscr...@googlegroups.com

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com

Reply via email to