简体   繁体   English

Selenium IDE:如何同时迭代 2 个列表? 我无法对集合进行迭代

[英]Selenium IDE: How do I iterate simultaneously over 2 lists? I can't get the iterate over a collection to work

I have a problem with selenium IDE, I need it to iterate over a list that has 2 values (for example username and password).我对 selenium IDE 有疑问,我需要它来遍历具有 2 个值(例如用户名和密码)的列表。 I saw a section on selenium IDE's website for iterating over a collection but it does not seem to work for me: https://www.selenium.dev/selenium-ide/docs/en/introduction/control-flow我在 selenium IDE 的网站上看到了一个用于迭代集合的部分,但它似乎对我不起作用: https ://www.selenium.dev/selenium-ide/docs/en/introduction/control-flow

These are the 2 versions I tried, in the first one I tried to make a list but I am not sure I did correctly.这些是我尝试过的 2 个版本,在第一个版本中我尝试列出一个列表,但我不确定我做得是否正确。 In the 2 nd version of the code I try iterating over the 2nd list using array position (${MyArray}[0]}, it only works when the value is a number, when I try to replace it with ${count} it does not work anymore.在代码的第二个版本中,我尝试使用数组位置(${MyArray}[0]} 迭代第二个列表,它仅在值是数字时才有效,当我尝试用 ${count} 替换它时不再工作了。

Any idea what I can do?知道我能做什么吗? Any help would be appreciated?任何帮助,将不胜感激?

在此处输入图像描述

在此处输入图像描述

Okay I finally found the solution for this in a reply to a blog post about arrays in Selenium IDE.好的,我终于在一篇关于 Selenium IDE 中数组的博客文章的回复中找到了解决方案。 You can't really do this through the forEach command, you have to use a javascript snippet through execute script command in order to iterate over the array.您不能通过 forEach 命令真正做到这一点,您必须通过执行脚本命令使用 javascript 片段来迭代数组。 You can find the full answer here: https://sitegrammar.com/selenium-ide-arrays/#comment-91您可以在这里找到完整的答案: https ://sitegrammar.com/selenium-ide-arrays/#comment-91

This is the image of the full code that works: https://i.imgur.com/GmN1FK8l.png这是有效的完整代码的图像: https ://i.imgur.com/GmN1FK8l.png

在此处输入图像描述

I also figured out what I've been doing wrong when trying to iterate over a collection.我还弄清楚了在尝试迭代集合时我做错了什么。 This is how the array should have been written:数组应该是这样写的:

execute script |执行脚本 | return [{name:"Angela",age:"55"},{name:"Linda",age:"50"}] |返回 [{name:"Angela",age:"55"},{name:"Linda",age:"50"}] | MyArray我的数组

forEach |为每个 | MyArray |我的数组 | iterator迭代器

echo |回声 | ${iterator.age} end ${iterator.age} 结束

This works for iterating over 2 arrays at the same time.这适用于同时迭代 2 个数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM