The Issue 

Validating HTML tables when testing requires a different approach than other basic web eleements. HTML tables have specific Watir Webdriver commands that allow for a variety of convenient validations, including row/column count and text validation. Lets take a look!

The Answer

The above commands span a plethora of options for table interactions. Validations involving row/column count are the jumping off point basic for table validation. Lets use a few of these in an example.

The Code

This will navigate the browser to the table page and validate the rows/columns.

The Result

We can save the file (textfieldtest.rb) and run it from the command line, with the following result:

  • Browser opens
  • Browser navigates to the HTML example page
  • Validates column amount
  • Validates row amount

The Takeaway

Whether you need to validate text or row length, HTML tables that you encounter will have a multitude of variables to test. Tackling these variables requires the utilization of specific Watir Webdriver commands for tables, which  will prove useful across your testing.