Created
September 17, 2013 04:49
-
-
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.
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 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