Skip to content

Instantly share code, notes, and snippets.

@samwgoldman
Created August 8, 2011 08:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samwgoldman/1131386 to your computer and use it in GitHub Desktop.
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
# 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