Skip to content

Instantly share code, notes, and snippets.

@p0deje
Last active December 10, 2015 02:38
Show Gist options
  • Save p0deje/4369348 to your computer and use it in GitHub Desktop.
Save p0deje/4369348 to your computer and use it in GitHub Desktop.
require 'watir-webdriver'
begin
browser = Watir::Browser.new
browser.goto "data:text/html,#{DATA.read}"
rows = browser.table.rows
rows.each do |tr|
p tr.td(index: 2).text
end
ensure
browser.quit
end
#
# Produces:
#
# ❯ ruby test.rb
# "cell3"
# "cell7"
#
__END__
<html>
<table id="table1" class="class1">
<thead>...<thead>
<tbody>
<tr id="1">
<td class>cell1</td>
<td class>cell2</td>
<td class>cell3</td>
<td class>cell4</td>
</tr>
<tr id="2">
<td class>cell5</td>
<td class>cell6</td>
<td class>cell7</td>
<td class>cell8</td>
</tr>
</tbody>
</table>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment