Created
August 8, 2011 08:06
-
-
Save samwgoldman/1131386 to your computer and use it in GitHub Desktop.
Ruby method that builds XPath which finds fields within tables as labeled by the table headers
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
# Only works with column oriented tables | |
# Doesn't support colspan | |
def tabular_field(locator) | |
preceding_cells = 'count(ancestor::td[1]/preceding-sibling::td)' | |
preceding_headers = "count(ancestor::table[1]/thead/th[normalize-space(.) = '#{locator}']/preceding-sibling::th)" | |
".//input[#{preceding_cells} = #{preceding_headers}]" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment