How to change value in xpath

Hello I try to change a number value in loop into the xpath but it isn’t work. I would like change this number xpath=//*[@id=“app”]/div[1]/ul/li[*HERE*]/div/a the number is loopcounter. I thought configure element li like with number of loopcounter.
I have a example to understand good.

{
      "Command": "while_v2",
      "Target": "(${loopcounter} <= 5)",

      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "Loop = ${loopcounter}",
      "Value": "blue"
    },
    {
      "Command": "executeScript",
      "Target": "return Number ${loopcounter}+1",
      "Value": "loopcounter"
    },
    {
      "Command": "clickAndWait",
      "Target": "xpath=//*[@id=\"app\"]/div[1]/ul/li[\"${loopcounter}\"]/div/a",
      "Value": ""
    },
    {
      "Command": "endWhile",
      "Target": "",
      "Value": ""
    }

Your code is corrent what is the problem ?

I usually prefer using gotoif and label to create a loop.

This is macro code working

{
  "Name": "Loop-Incremental",
  "CreationDate": "2020-1-13",
  "Commands": [
    {
      "Command": "store",
      "Target": "true",
      "Value": "!errorignore"
    },
    {
      "Command": "store",
      "Target": "0",
      "Value": "loopcounter"
    },
    {
      "Command": "label",
      "Target": "restart",
      "Value": ""
    },
    {
      "Command": "executeScript",
      "Target": "return Number ${loopcounter}+1",
      "Value": "loopcounter"
    },
    {
      "Command": "echo",
      "Target": "Loop = ${loopcounter}",
      "Value": " #shownotification"
    },
    {
      "Command": "clickAndWait",
      "Target": "xpath=//*[@id=\"app\"]/div[1]/ul/li[\"${loopcounter}\"]/div/a",
      "Value": ""
    },
    {
      "Command": "gotoIf_v2",
      "Target": "(${loopcounter} <= 5)",
      "Value": "restart"
    }
  ]
}
1 Like

Not working for me. I had to make this, into the loop:

{
  "Command": "executeScript",
  "Target": "var string = '//*[@id=\"app\"]/div[1]/li[' + ${loopcounter} + ']/div/a'; return string;",
  "Value": "myPath"
},
{
  "Command": "click",
  "Target": "xpath=${myPath}",
  "Value": ""
}

Thanks for advice ‘gotoif’ is very interesting!!

My macro code is correct but i do not know your code

{
  "Command": "executeScript",
  "Target": "var string = '//*[@id=\"app\"]/div[1]/li[' + ${loopcounter} + ']/div/a'; return string;",
  "Value": "myPath"
},

Try another xpath, for the same element there are multiple xpaths

I do not know what is your function inside executeScript