Extract from JavaScript

Command value: extractEval

Runs JavaScript in the page and saves the returned value into a variable.

Fields

FieldJSON propertyDescription
Variable Namevariable_nameName to store the result under. Reference it in later steps as {{NAME}}.
JavaScript CodevalueCode that runs in the page. Use return to send a value back.

Usage

  • Use it for values that are not visible text, such as a data attribute, the current URL or a localStorage entry.

Example step (JSON)

{
  "command": "extractEval",
  "variable_name": "CART_ID",
  "value": "return localStorage.getItem('cartId');"
}

Playwright equivalent

const CART_ID = await page.evaluate(() => {
  return localStorage.getItem('cartId');
});

Common options

  • Make this step optional (Continue on failure): when checked, a failure in this step is recorded and the test continues with the next step.
  • Execute step when JavaScript returns true: runs the step only when the JavaScript condition returns true. Otherwise the step is skipped.

See conditional steps and variables for details.