开发者

How to find a particular table cell in Watir

开发者 https://www.devze.com 2023-01-02 14:29 出处:网络
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

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, 开发者_StackOverflowbut 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.


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


try this

cell = browser.div(:id,'Menu').cell(:text,'New!')
cell.click

and, maybe you lost closing ']' ?

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

精彩评论

暂无评论...
验证码 换一张
取 消