问题
In Selenium IDE 3.7.4 I'd like to make a loop to do click on several links that have similar Xpath. For this I think in create an array but trying with a simple array with the settings (Command,Target, Value) as below is not working.
+----------------+---------------------------------------+---------+
| Command | Target | Value |
+----------------+---------------------------------------+---------+
| execute script | var a = "A|B|C".split("|"); return a; | arr |
+----------------+---------------------------------------+---------+
| execute script | return 0 | counter |
+----------------+---------------------------------------+---------+
| while | ${counter} < 3 | |
+----------------+---------------------------------------+---------+
| echo | "Element = " + ${arr[${counter}]} | |
+----------------+---------------------------------------+---------+
| execute script | return ${counter} + 1 | counter |
+----------------+---------------------------------------+---------+
| end | | |
+----------------+---------------------------------------+---------+
The expected output for this test would be:
Element = A
Element = B
Element = C
And I'm getting this output:
"Element = " + ${arr[${counter}]}
"Element = " + ${arr[${counter}]}
"Element = " + ${arr[${counter}]}
How can I handle arrays and print their elements in Selenium IDE? I only found some question here regarding this but with a older version
of Selenium IDE that had other commands like getEval
that doesn't exist in latest version.
Thanks in advance for any help.
UPDATE
Thanks to Jim's answer I was able to complete a working array example on Selenium IDE. The code is like below
{
"version": "2.0",
"name": "Array",
"url": "https://www.seleniumhq.org",
"tests": [{
"name": "Untitled",
"commands": [{
"command": "open",
"target": "https://www.seleniumhq.org",
"targets": [],
"value": ""
}, {
"command": "executeScript",
"target": "var a = \"projects|download|documentation\".split(\"|\"); return a;",
"targets": [],
"value": "arr"
}, {
"command": "executeScript",
"target": "return 0",
"targets": [],
"value": "counter"
}, {
"command": "pause",
"target": "4000",
"targets": [],
"value": ""
}, {
"command": "while",
"target": "${counter} < 3",
"targets": [],
"value": "counter"
}, {
"command": "executeScript",
"target": "return \"css=#menu_\" + ${arr}[${counter}] + \" > a\";",
"targets": [],
"value": "output"
}, {
"command": "click",
"target": "${output}",
"targets": [],
"value": ""
}, {
"command": "pause",
"target": "3000",
"targets": [],
"value": ""
}, {
"command": "executeScript",
"target": "return ${counter} + 1;",
"targets": [],
"value": "counter"
}, {
"command": "end",
"target": "",
"targets": [],
"value": ""
}]
}],
"suites": [{
"name": "Default Suite",
"persistSession": false,
"parallel": false,
"timeout": 300,
"tests": ["78b402ba-8dfa-47d6-bee8-7a0d928db6f1"]
}],
"urls": ["https://www.seleniumhq.org/"],
"plugins": []
}
来源:https://stackoverflow.com/questions/56266336/how-to-handle-arrays-in-selenium-ide-3-7-4