Kantu(Selenium):如何将元素推送到现有数组
Kantu (Selenium): How to push Element to existing Array
如何在 Kantu 中向现有数组添加元素
我做了下面的代码,但是 name2,length2,namesContent2 和预期的不一样
{
"Name": "testArrayPush",
"CreationDate": "2019-8-28",
"Commands": [
{
"Command": "storeEval",
"Target": "new Array ('cat','dog','fish','dog','','frog','dog','horse','??elephant')",
"Value": "names"
},
{
"Command": "storeEval",
"Target": "storedVars['names'].length",
"Value": "length"
},
{
"Command": "storeEval",
"Target": "storedVars['names']",
"Value": "namesContent"
},
{
"Command": "echo",
"Target": "array names = ${namesContent}",
"Value": ""
},
{
"Command": "echo",
"Target": "array length = ${length}",
"Value": ""
},
{
"Command": "storeEval",
"Target": "[storedVars['names'],'Thomas']",
"Value": "names2"
},
{
"Command": "storeEval",
"Target": "storedVars['names2'].length",
"Value": "length2"
},
{
"Command": "storeEval",
"Target": "storedVars['names2']",
"Value": "namesContent2"
},
{
"Command": "echo",
"Target": "array names2 = ${namesContent2}",
"Value": ""
},
{
"Command": "echo",
"Target": "array length2 = ${length2}",
"Value": ""
}
]
}
这是输出,但我希望得到一个长度为 10 的新数组
怎么做?
[status]
Playing macro testArrayPush
[info]
Executing: | storeEval | new Array ('cat','dog','fish','dog','','frog','dog','horse','??elephant') | names |
[info]
Executing: | storeEval | storedVars['names'].length | length |
[info]
Executing: | storeEval | storedVars['names'] | namesContent |
[info]
Executing: | echo | array names = ${namesContent} | |
[echo]
array names = cat,dog,fish,dog,,frog,dog,horse,??elephant
[info]
Executing: | echo | array length = ${length} | |
[echo]
array length = 9
[info]
Executing: | storeEval | [storedVars['names'],'Thomas'] | names2 |
[info]
Executing: | storeEval | storedVars['names2'].length | length2 |
[info]
Executing: | storeEval | storedVars['names2'] | namesContent2 |
[info]
Executing: | echo | array names2 = ${namesContent2} | |
[echo]
array names2 = cat,dog,fish,dog,,frog,dog,horse,??elephant,Thomas
[info]
Executing: | echo | array length2 = ${length2} | |
[echo]
array length2 = 2
[info]
Macro completed (Runtime 5.47s)
第一个数组没问题,长度为9个元素
我想向这个现有数组添加几个新元素(稍后在代码循环中添加它们。
但是第二个数组只有两个元素,第一个元素是旧数组,第二个元素是新添加的元素
如何正确地做到这一点?
如果要保持原数组不变,可以使用concat将新元素推送到旧数组的副本。
所以
{
"Command": "storeEval",
"Target": "[storedVars['names'],'Thomas']",
"Value": "names2"
}
转为
{
"Command": "storeEval",
"Target": "storedVars['names'].concat('Thomas')",
"Value": "names2"
},
输出:
[info]
Executing: | storeEval | storedVars['names'].concat('Thomas') | names2 |
[info]
Executing: | storeEval | storedVars['names2'].length | length2 |
[info]
Executing: | storeEval | storedVars['names2'] | namesContent2 |
[info]
Executing: | echo | array names2 = ${namesContent2} | |
[echo]
array names2 = cat,dog,fish,dog,,frog,dog,horse,??elephant,Thomas
[info]
Executing: | echo | array length2 = ${length2} | |
[echo]
array length2 = 10
如何在 Kantu 中向现有数组添加元素
我做了下面的代码,但是 name2,length2,namesContent2 和预期的不一样
{
"Name": "testArrayPush",
"CreationDate": "2019-8-28",
"Commands": [
{
"Command": "storeEval",
"Target": "new Array ('cat','dog','fish','dog','','frog','dog','horse','??elephant')",
"Value": "names"
},
{
"Command": "storeEval",
"Target": "storedVars['names'].length",
"Value": "length"
},
{
"Command": "storeEval",
"Target": "storedVars['names']",
"Value": "namesContent"
},
{
"Command": "echo",
"Target": "array names = ${namesContent}",
"Value": ""
},
{
"Command": "echo",
"Target": "array length = ${length}",
"Value": ""
},
{
"Command": "storeEval",
"Target": "[storedVars['names'],'Thomas']",
"Value": "names2"
},
{
"Command": "storeEval",
"Target": "storedVars['names2'].length",
"Value": "length2"
},
{
"Command": "storeEval",
"Target": "storedVars['names2']",
"Value": "namesContent2"
},
{
"Command": "echo",
"Target": "array names2 = ${namesContent2}",
"Value": ""
},
{
"Command": "echo",
"Target": "array length2 = ${length2}",
"Value": ""
}
]
}
这是输出,但我希望得到一个长度为 10 的新数组
怎么做?
[status]
Playing macro testArrayPush
[info]
Executing: | storeEval | new Array ('cat','dog','fish','dog','','frog','dog','horse','??elephant') | names |
[info]
Executing: | storeEval | storedVars['names'].length | length |
[info]
Executing: | storeEval | storedVars['names'] | namesContent |
[info]
Executing: | echo | array names = ${namesContent} | |
[echo]
array names = cat,dog,fish,dog,,frog,dog,horse,??elephant
[info]
Executing: | echo | array length = ${length} | |
[echo]
array length = 9
[info]
Executing: | storeEval | [storedVars['names'],'Thomas'] | names2 |
[info]
Executing: | storeEval | storedVars['names2'].length | length2 |
[info]
Executing: | storeEval | storedVars['names2'] | namesContent2 |
[info]
Executing: | echo | array names2 = ${namesContent2} | |
[echo]
array names2 = cat,dog,fish,dog,,frog,dog,horse,??elephant,Thomas
[info]
Executing: | echo | array length2 = ${length2} | |
[echo]
array length2 = 2
[info]
Macro completed (Runtime 5.47s)
第一个数组没问题,长度为9个元素
我想向这个现有数组添加几个新元素(稍后在代码循环中添加它们。
但是第二个数组只有两个元素,第一个元素是旧数组,第二个元素是新添加的元素
如何正确地做到这一点?
如果要保持原数组不变,可以使用concat将新元素推送到旧数组的副本。
所以
{
"Command": "storeEval",
"Target": "[storedVars['names'],'Thomas']",
"Value": "names2"
}
转为
{
"Command": "storeEval",
"Target": "storedVars['names'].concat('Thomas')",
"Value": "names2"
},
输出:
[info]
Executing: | storeEval | storedVars['names'].concat('Thomas') | names2 |
[info]
Executing: | storeEval | storedVars['names2'].length | length2 |
[info]
Executing: | storeEval | storedVars['names2'] | namesContent2 |
[info]
Executing: | echo | array names2 = ${namesContent2} | |
[echo]
array names2 = cat,dog,fish,dog,,frog,dog,horse,??elephant,Thomas
[info]
Executing: | echo | array length2 = ${length2} | |
[echo]
array length2 = 10