Skip to main content

Snapshots and refs

Take a snapshot before you click. The snapshot is the list of elements you can act on. Each interactive line ends with a ref such as [ref=e3].

npx wdio session open chrome http://localhost:3000
npx wdio session snapshot --interactive

A line looks like button "Add to cart" [ref=e3]. The next command uses that ref:

npx wdio session click e3

Refs come from the latest snapshot. After navigation, snapshot again. An old ref fails with REF_STALE. An unknown ref fails with REF_NOT_FOUND.

What to run​

CommandUse it for
snapshot --interactiveThe elements you can act on, each with a ref
find "Add to cart"One line from a fresh snapshot
diffWhat changed since the previous snapshot
screenshotLayout. Skip it when a snapshot answers the question
sourceThe page HTML or the native XML

snapshot without --interactive includes more of the tree. Prefer --interactive when you are about to click or type.

On Android, iOS, macOS and Windows the snapshot comes from the Appium page source. Two controls that share an accessibility id stay separate refs when the rest of their selectors differ. snapshot --scope e3 limits the tree to that ref.

Native taps​

Web sessions use click. Mobile and native desktop sessions use tap on the same ref:

npx wdio session open android --app ./shop.apk
npx wdio session snapshot --interactive
npx wdio session tap e3

Troubleshooting​

MessageWhat to do
REF_STALEThe element from the last snapshot is gone. Run snapshot and use a new ref.
REF_NOT_FOUNDThat id was never in this session. The ref in your command does not match the latest snapshot.
NO_MATCHfind did not see that text. Snapshot and read the names that are actually there.

Next steps​

  • Run code — assertions and steps that are more than one command
  • Commands — snapshot, find, diff, screenshot and source flags

Welcome! How can I help?

WebdriverIO AI Copilot