Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert a Capybara table to something you can diff with a Cucumber table
# change 'table' to a more specific selector when the page will have more than one table
find('table').all('tr').map { |row| row.all('th, td').map { |cell| cell.text.strip } }
@dennisreimann

This comment has been minimized.

dennisreimann commented Oct 20, 2011

Thank you for providing this snippet. I had to call strip on cell.text otherwise it contained line breaks in some cases.

@richardlawrence

This comment has been minimized.

Owner

richardlawrence commented Dec 15, 2011

Thanks, @dbloete, I've updated the snippet to include strip.

@gauravsaini23

This comment has been minimized.

gauravsaini23 commented Dec 15, 2011

But Why remove tableish ?

@dennisreimann

This comment has been minimized.

dennisreimann commented Dec 15, 2011

Because tablish isn't as flexible as the Capybara finders and like you see: It's easy to roll it yourself.

@asiddiq

This comment has been minimized.

asiddiq commented May 24, 2014

How does capybara handle elements inside a table cell/row? Is there a quick way to select a checkbox or a link based on cell data? For example, I want to look through the table data and once I find it in row X and there exists a checkbox, and I want to click on that checkbox. What's capybara's best way to handle this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment