tags:

views:

352

answers:

1

Using Watir to regression test some changes: I want to 'click' a row in a typical old style web page menu, where the menu is a table of tables. In this particular example, the table cell contains the menu item, and the row, which only consists of the one cell, has an onclick handler. I thought I could

cell = browser.element_by_xpath("//div[@id='Menu']/descendant::td[text()='New!'")

and use the cell to get the parent row, but I get the message

c:/ruby/lib/ruby/1.8/rexml/parsers/xpathparser.rb:330:in 'Predicate': undefined method `[]' for nil:NilClass (NoMethodError)

which makes no sense to me.

+1  A: 

We really need more detail before before an answer can be given

Generally speaking there are a few ways to deal with tables. You can use absolute indexes to the row and column numbers if that will always be the same, but a lot of times that's not the case.

If there's known (unique) text on the row somewhere, and the column of the cell is known, then you can often work via using a regular expression to identify the row with the known (and unique) text, and then identify the needed cell via it's 'column' within the row.

browser.row(:text, /my search text/).cell(:index, 2) # 2nd cell in the row that contains text matched by the regex

Chuck van der Linden