Skip to content

Instantly share code, notes, and snippets.

@garrow
Created September 17, 2013 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save garrow/6590179 to your computer and use it in GitHub Desktop.
Save garrow/6590179 to your computer and use it in GitHub Desktop.
Adding a `within_cell` Capybara helper. We use this within our Turnip specs to find a particular cell within a particular column within a table.
def within_cell(row, column)
within_row(row) do
within_column(column) { yield }
end
end
def within_column(column)
# Find the table column offset for the column header, then grab the columns' cells at that offset.
# Adapted from http://stackoverflow.com/questions/14745478
within(:xpath, "//table/tbody/tr/td[count(//table/thead/tr/th[normalize-space()='#{column}']/preceding-sibling::th)+1]") do
yield
end
end
def within_row(name)
within(:xpath, "//tr[td='#{name}']") { yield }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment