To handle tables with a variable number of columns in UiPath, here’s a straightforward approach:
Determine the Number of Columns Dynamically:
Use the Find Children activity to get all <th> or <td> elements within the table’s header row. This will give you the exact number of columns. Just set the Find Children activity to target the header row (using the right selector for <tr>), and count the resulting elements to identify how many columns are in the table. Set Up the Extract Table Data Activity with a Flexible Selector:
In the Extract Table Data wizard, make sure to set up the selector to be flexible. Replace any static attributes related to column count with wildcards (*). For instance, use a dynamic setup for tableRow and tableCol attributes, which will let the extraction adjust automatically based on the table’s structure. Sample Dynamic Selector:
Here’s an example of a dynamic selector structure that should work regardless of column count:
Once the selector is set up, use the Extract Table Data wizard to refine the extraction as needed. If it’s struggling to capture data correctly, try pairing it with the Anchor Base activity for more accuracy—especially if there are any static elements nearby that you can anchor to.