Spying a Browser App That Re-renders Its Grid
A developer is automating a web-based claims portal. The claims table is rendered by a JavaScript framework that rebuilds the DOM whenever the user sorts or filters, and element attributes such as a generated id change on every rebuild. The developer spied the table using HTML mode and captured a path that includes the generated id. In test, the process reads the first row correctly, but in production it intermittently throws 'element not found' after a filter is applied, and sometimes reads the wrong row. The portal also has a login page that issues a session token, and a separate REST endpoint the team could call instead. The developer wants to switch everything to region mode and add fixed waits of 5 seconds after each click.
1. Evaluate the proposed fixes (region mode plus fixed waits) and recommend a more robust spying and wait strategy.
Read the worked answer
Region mode plus fixed waits treats symptoms, not causes. Region mode matches on image or text within a screen area; it is brittle when the grid scrolls, when row heights change, or when the portal is used at a different resolution or zoom on the runtime machine. Fixed 5-second waits do not solve a race - they merely make it less likely - and they add 5 seconds to every click, which on a large claim volume destroys throughput. When the DOM rebuilds, the element genuinely does not exist for a moment, so a longer wait may still land in the gap.
The root problem is the match attributes. The developer should re-spy the grid using attributes that are stable across rebuilds: the column header text, the row's business key (claim reference), and relative position within the table, rather than the generated id. Use dynamic match attributes with wildcards only where the stable part is known, and prefer matching on accessible names or data attributes the framework preserves. For row selection, match the row by its claim reference text rather than by index, because index shifts when the filter changes the result order.
Replace fixed waits with a wait-for-condition: poll for the grid to be present and for the expected row count or a specific claim reference to appear, with a timeout. That is both faster and deterministic. Finally, since a REST endpoint exists, evaluate using it for data retrieval and reserving UI automation for actions that have no API - that removes the DOM-rebuild problem entirely for the read path.
2. The team asks whether to keep the UI login or authenticate against the API. What factors decide this, and what risks must be managed either way?
Read the worked answer
The deciding factors are stability, security, and auditability. An API token flow is far more stable than driving a login form whose layout and session handling can change without notice, and it avoids storing a password in a process that must type it into a browser. It also tends to be faster and easier to run headless across many sessions. The UI login should be kept only where the API cannot perform the needed action or where the portal enforces interactive login for compliance reasons.
If the API route is chosen, manage these risks: credential storage must use the platform's credential manager, never hard-coded in the process or in a data item that gets logged; tokens must be requested per session, cached only for their lifetime, and refreshed on expiry rather than reused indefinitely; and the token must never appear in exception detail or logs. Confirm with the application owner that API use is permitted under the licence and terms, and that rate limits are understood.
If the UI login is kept, manage session reuse carefully: log in once per session and reuse the session for multiple items rather than logging in per item, detect session expiry explicitly and re-authenticate, and ensure logout or session cleanup so that a crashed session does not hold a lock. In both cases, record which identity performed each action for audit. The choice should be documented as an architecture decision with the reason, so a future developer does not silently switch paths.