0

I use Javascript with PhantomJS.
I know my DOM contain many attribute like foo_0, foo_1, … I know I can access them with (I test it, It's work)

window.foo_1.src
window['foo_1'].src

I would like iterate to access all attributes. Something like this:

var i = 0
do {
    // some stuff
    bar = page.evaluate(function(){
        return window['foo_' + i].src
    })
    i++
} while ( <cond> )

'foo_1' work fine but 'foo_' + i don't.

Do you have any idea ? I seems not know.

Pinkilla
  • 190
  • 8

1 Answers1

0

Exactly. Variable i is not know in function evaluate. Add argument and it's work ! Just like this.

var i = 0
do {
    // some stuff
    bar = page.evaluate(function(i){
        return window['foo_' + i].src
    }, i)
    i++
} while ( <cond> )
Pinkilla
  • 190
  • 8