Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessing variables from executescript function

I'm looking to set some data dynamically during testing using browser.executescript. Something like:

var x;
browser.executeScript(function () {
  var something = x;
});

But x seems to be out of the scope of the function being run. Is there a way for me to pass arguments that will be in the inner scope?

Any help greatly appreciated C

like image 617
Cathal Avatar asked Jun 01 '26 13:06

Cathal


1 Answers

Pass the arguments inside arguments:

Any arguments provided in addition to the script will be included as script arguments and may be referenced using the arguments object. Arguments may be a boolean, number, string, or webdriver.WebElement. Arrays and objects may also be used as script arguments as long as each item adheres to the types previously mentioned.

var x;
browser.executeScript(function (arguments) {
  var something = arguments[0];
}, x);
like image 107
alecxe Avatar answered Jun 04 '26 01:06

alecxe