Hi Dave, Thanks for your answer.
I am very new to this, however I can see what you are getting at :-). Slight problem on the solution you recommended. If you compare the source of these two links then you will see that <div id="contentalt"> appears both when the table appears (i.e. the postal address is found) and when the postal address is not found. http://www.mycounciltax.org.uk/results?postcode=CV56bz&search=Search<view-source:http://www.mycounciltax.org.uk/results?postcode=CV56bz&search=Search> http://www.mycounciltax.org.uk/results?postcode=EX99AE&search=Search So I guess what I want to test is whether the table element exists? and when there is no table I just want the script to end. However if there is a table I want to out the contents into excel. I have tried putting the following script together but I don't think this is correct. I am sure I have made a mistake with testing the for the table element. if browser.table.trs.collect {|tr| [tr[0].text, tr[1].text, tr[2].text]}.exists? // test to see if this exists then content = browser.table.trs.collect {|tr| [tr[0].text, tr[1].text, tr[2].text]} // if it does exist then set the variable and output to excel See the full script below. I plan to run this in one go (not in cmd but from a .rb file). I am sure there is a better way of running these two scripts together but I am new to this and trying to build myself up :-). Any ideas where I am going wrong? Many thanks in advance. require "watir-webdriver" browser = Watir::Browser.new :ff browser.goto " http://www.mycounciltax.org.uk/results?postcode=EX99AE&search=Search" if browser.table.trs.collect {|tr| [tr[0].text, tr[1].text, tr[2].text]}.exists? then content = browser.table.trs.collect {|tr| [tr[0].text, tr[1].text, tr[2].text]} require 'win32ole' application = WIN32OLE.new('Excel.Application') application.visible = TRUE workbook = application.Workbooks.Add(); worksheet = workbook.Worksheets(1); worksheet.visible row = 1; column = 0 content.each do |array| array.each do |element| worksheet.Cells(1,1).offset(row,column).value = element #.offset(row,column) column += 1 end row += 1 column = 0 end else end browser.goto " http://www.mycounciltax.org.uk/results?postcode=CV56BZ&search=Search" if browser.table.trs.collect {|tr| [tr[0].text, tr[1].text, tr[2].text]}.exists? then content = browser.table.trs.collect {|tr| [tr[0].text, tr[1].text, tr[2].text]} require 'win32ole' application = WIN32OLE.new('Excel.Application') application.visible = TRUE workbook = application.Workbooks.Add(); worksheet = workbook.Worksheets(1); worksheet.visible row = 1; column = 0 content.each do |array| array.each do |element| worksheet.Cells(1,1).offset(row,column).value = element #.offset(row,column) column += 1 end row += 1 column = 0 end else end On Sat, Feb 4, 2012 at 5:28 AM, Dave McNulla <[email protected]> wrote: > I tried your URL. It said there were no properties at that postal code. > Can't you look for <div id="contentalt">? > > unless browser.div(:id => 'contentalt).exists? do > #loops here. > end > > Dave > > -- > 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] > -- 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]
