【发布时间】:2021-08-02 18:23:30
【问题描述】:
给定以下 json:
{
"contract": [
{"fieldName": "contractYear", "fieldValue": "2020"},
...
],
"ruleSet": [
...
]
}
还有以下内容:
staticCompany.contract.forEach(index => {
if (this.index.fieldName.getText() == index.fieldValue) {
validationCount ++;
}
});
我知道这个事实。操作员不会喜欢我正在尝试做的事情。有没有办法提取 fieldName 以便我可以使用它来点击同名的选择器?
我在 wdio v5 的 Node 12.13 中执行此操作。
【问题讨论】:
-
您的意思是
this[index]而不是this.index? -
根本不需要
this- 只需将this.index替换为index即可。但是index是实际数组元素的名称选择不佳 -
实际上,经过反思,这可能不是您想要的 - 但我不知道您确实想要什么。您能否编辑您的问题以使输入和预期输出更清晰?
-
fieldName值是否真的等于fieldValue值? -
在您的
forEach()语句中,this指的是window。此外, for each 仅传递数组的索引号。如果您想查看forEach()中的值,您需要像这样传递元素:forEach((element) => { ... } )。见:developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…
标签: javascript wdio-v5