accessing variables from executescript function

六月ゝ 毕业季﹏ 提交于 2019-12-04 13:20:55

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);

In addition to @alecxe's answer, if you want more readable code, and you can support es6 this seems like a nice option. More info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment

var my, params, go, here;
browser.executeScript(function ([my, params, go, here]) {
  var something = here;
}, [my, params, go, here]);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!