0
votes

I'm writing a Watir program to extract a specific number from a dynamically-generated table. The number is always in the second column of the fourth-to-last row in the table, but I'm getting the following error when trying to access the general table element:

Watir::Table: located: false; {:id=>"tContenido", :tag_name=>"table"}

Code

require 'rubygems'
require 'watir'
browser = Watir::Browser.new :firefox
$log = Logger.new('logs\test.log')
$log.info("TEST")
$log.info browser.table(:id, 'tContenido')

HTML Structure of the target page (1) HTML Structure of the target page (1)

HTML Structure of the target page (2) HTML Structure of the target page (2)

Any help would be greatly appreciated, thanks in advance!

2
Did you visit the page? I didn't see method goto like this: browser.goto "www.google.com" - fongfan999
that's not an error, just the output of the Element#inspect. What happens when you do browser.table(:id, 'tContenido').exists? - titusfortner
@fongfan999 yes of course, my bad. I'm doing other things in my code so i simplified it and forgot to include that line - Alonso Iturbe
@titusfortner it outputs true. I wrote puts browser.table(:id, 'tContenido').text and i got the whole table, but i can't seem to access its internal elements, i keep getting a timeout error - Alonso Iturbe
Elements in Watir are lazy loaded so seeing "located: false" just means you haven't tried to do anything with the element yet that required it to be looked up. So finding the table element itself isn't the problem, just figuring out what you want inside the table element. - titusfortner

2 Answers

2
votes

I think this is the one you are looking for:

browser.table(id: 'tContenido').tr(class: 'tr_gris', index -1).td(index: 1).text

Alternately, if you are having problems with a table, you can just put everything into an array of Hashes:

browser.table(id: 'tContenido').hashes
0
votes

You can write the following WATIR code

puts b.table(id: 'tContenido').trs[-4].tds[2].text