16 Aug 2012, 19:44
Generic-user-small

Chuck van der Linden (3 posts)

In the Parsing HTML tables recipe you are identifying the table by ordinal position on the page. That tends to create a brittle test that will break if anyone adds or removes another table on the page anywhere above the one used in the test.

Would it be better to show creating more testable HTML and assigning a Name or ID attribute to the table element which would then allow:

  • identifying the table in a way that results in more readable code
  • identifying in a way that won’t be as likely to break if page content is expanded
21 Aug 2012, 04:53
Mr_sketchy_pragsmall

Ian Dees (192 posts)

Hi, Chuck.

You’re right: the best approach is to identify HTML elements by name, ID, or (in a pinch) CSS attribute. Nearly anything is better than a raw ordinal. We were using it here only as an example of dirty HTML that we (hypothetically) didn’t have direct control over. I should have explained in the text why we tested it this way, and will correct that in the next beta.

Good catch, and thank you.

Sincerely,

Ian

  You must be logged in to comment