How to get number out of xpath

Out of xpath that contains “− 45%” I only want to take out the “45” part

I’ve tried these but it didn’t work :

  "Command": "storeText",
  "Target": "xpath=//*[@id=\"content\"]/div/div[3]/div[2]/div/div/div/div/a/div/div[3]/div/div/div[2]/span",
  "Value": "percent",
  "Description": ""
  "Command": "executeScript_Sandbox",
  "Target": "var s = ${percent}; s=s.substring(2,2)",
  "Value": "number",
  "Description": ""
  "Command": "echo",
  "Target": "${number}",
  "Value": "lime",
  "Description": ""

storeText correctly shows “− 45%”
echo shows “undefined”

Your code is almost correct, but in the executeScript_Sandbox expression the return s; part is missing. That is why the number variable is undefined

See also: Getting the last element of a split string - #2 by admin

1 Like