gpt4 book ai didi

javascript - 在 CasperJS 的 fillSelectors 中使用变量 key

转载 作者:行者123 更新时间:2023-12-02 17:01:57 25 4
gpt4 key购买 nike

我想使用变量作为 fillSelectors() 方法输入标记的键:

this.fillSelectors(formLogin, { variable1:myEmail},false)

表单名称和值(myEmail)是变量,但键(variable1)不是。作为键,需要一个字符串,否则我会收到错误:

 CasperError: Errors encountered while filling form: no field matching css selector "inpu1" in form

你能帮忙吗?

最佳答案

通过执行{variable1: myEmail},您将创建一个具有名为variable1的属性的对象。这与 { "variable1": myEmail } 完全相同,因为在 javascript 中,键每次都会被读取为字符串。这与 Python 等其他语言不同,在 Python 中,您可以将不同的对象作为键,而不仅仅是字符串。

你想要的是以不同的方式构建你的对象:

var obj = {};
obj[variable1] = myEmail; // here the value of variable1 is used, not its name
this.fillSelectors(formLogin, obj, false)

关于javascript - 在 CasperJS 的 fillSelectors 中使用变量 key,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25609946/

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