What is Execute Javascript on Element?

  • Hi

    Sorry I might flood this place with questions for a few days but once I am up to speed, I will help others out too

    I found this on the Russian Forum, what are the use cases for Execute Javascript on Element? as opposed to execute Javascript

    Does this method return html elements, say my query was >>CSS >> .example
    Which has 3 instances, does it do something like a forEach method?


  • @deliter

    what are the use cases for Execute Javascript on Element?

    Execute Javascript on Element and Javascript it almost the same, they executes js in browser context. But Execute Javascript on Element also exposes self variable. It holds reference for found element.

    For example to remove element you should call:


    The value returned by this function is the value of exression converted to string

    For example

    2+2 returns 4

    self.value returns actual edit box value from html page

    self.getAttribute("href") may return link url

    The expression may contain variables from BAS context, so

    var index = [[CYCLE_INDEX]]; document.querySelectorAll("a")[index].getAttribute("href")

    Will return url from link with index [[CYCLE_INDEX]]

    Here is example project on how to parse all links with Execute Javascript on Element, but of course, much better way is to use xpath.


  • thats very nice, thanks for the explanation

Log in to reply