从executioncript函数访问变量 [英] accessing variables from executescript function
问题描述
我希望在测试期间使用browser.executescript动态设置一些数据。类似于:
I'm looking to set some data dynamically during testing using browser.executescript. Something like:
var x;
browser.executeScript(function () {
var something = x;
});
但是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?
任何帮助都非常感谢
C
Any help greatly appreciated C
推荐答案
传递参数 参数
:
任何参数除了脚本之外,提供的内容将作为
脚本参数包含在内,并且可以使用arguments对象进行引用。
参数可以是布尔值,数字,字符串或webdriver.WebElement。
数组和对象也可以用作脚本参数,只要
每个项目都符合前面提到的类型。
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);
这篇关于从executioncript函数访问变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!