gpt4 book ai didi

javascript - 从 executescript 函数访问变量

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:58:50 25 4
gpt4 key购买 nike

我希望在测试期间使用 browser.executescript 动态设置一些数据。像这样的东西:

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

但是x似乎超出了正在运行的函数的范围。有没有办法让我传递将在内部范围内的参数?

非常感谢任何帮助C

最佳答案

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

关于javascript - 从 executescript 函数访问变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32502933/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com