How to handle Web Tables

While this is a nice guide, I do take issue with the “store all elements in a list, then iterate and do action x” approach in general. This has two glaring issues:

1.) Depending on the size of the table, and the number of elements the script writer actually cares about validating/manipulating, then getting every element of a table and storing them in a list might be unnecessarily expensive. What if I only care about one particular cell at any given moment?

2.) An even bigger problem is that this approach has a high risk of throwing a StaleElementException. After you build a list of elements, if the DOM changes in any way (page reload, async js function, etc), then your list will almost certainly contain stale elements, in which case you would need to rebuild the list anyway to account for it (which is just problem #1 again).

In my opinion, it’s much more efficient as well as less risky to provide a locator that takes row/column indeces as arguments, and locate individual table elements at the moment they are needed. This way you are only every parsing the DOM for a single element, and the chance that that one element will become stale is drastically reduced.

3 Likes