How to execute JS using execute_script which uses temporary variables in the script

Hi all,

I’m trying to execute the following script using execute_script command but the IDE throws me an error saying that “[error] Line 11: variable “V” is not defined”

I’m sure that the error is occurring due to line ‘let a = document.querySelector("#tile_${v[0]}-${v[1]} > div.panel.panel.details > div > p:nth-child(2)").innerHTML;’

The dom path of the element is dynamic and I’m using another function to get those values in an iterator but when I try to make a JS path using those values, it throws error.

Any suggestion please?

let iter = SpiralIterator([x, y])
let v
for (var i = 0; i < count; i++) {
    v = iter.next().value // here iter vaule is of the form [x,y]
    if (i != 0) {
        let c = 0
        let a = document.querySelector("#tile_${v[0]}-${v[1]} > div.panel.panel.details > div > p:nth-child(2)").innerHTML;
        for (let ct of cts) {
            if (a.indexOf(ct) > -1) {
                c = 1
                break
            }
        }
    }
}

Hey @newuserkantu!
I noticed your comments in many posts and they were really helpful to me being a beginner. Could you please have a look at this as well and suggest something. I would really appreciate that.

Hi

i don’t know the javascript code you are using and i can’t suggest a solution, i know ui vision quite well but i don’t know much javascript, i suggest you ask for help also in the stackoverflaw forum where there are many expert javascript users

I’m a long (long) way from a javascript expert but, I would say try changing all the let to var, so for example

let iter = SpiralIterator([x, y])
let v

var iter = SpiralIterator([x, y])
var v

It’s worth a try!