Created
June 13, 2012 21:36
-
-
Save dobbs/2926615 to your computer and use it in GitHub Desktop.
capybara acceptance spec helper for finding a cell in table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def find_by_row_identifier_and_column_name(row_identifier, column_name) | |
#XPath resources | |
# http://msdn.microsoft.com/en-us/library/ms256086.aspx | |
# | |
# Figure out the column number for the given column_name | |
# //th[contains(., 'Magic')] find the first TH whose enclosing EM is 'Magic' | |
# /preceding::th finds the collection of TH elements which appear before this one | |
# XML indexes start with 1 not 0, so we add 1 | |
column_number = 1 + all(:xpath, "//th[contains(., '#{column_name}')]/preceding::th").length | |
# //td[contains(., '303-555-1212')][1] find the first TD which contains the given row_identifier | |
# any text which is unique-per-row would due | |
# /parent::tr find the TR which encloses the unique TD we just found | |
# /td[#{column_number}] find the TD which is in the same column we located by name earlier | |
find(:xpath, "//td[contains(., '#{row_identifier}')][1]/parent::tr/td[#{column_number}]") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment