Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.