[英]while loop only runs once
I am trying to loop list A and compare each element in list A to list B looking for a match I can't figure out why this while loop is only executing once? 我试图循环列表A并将列表A中的每个元素与列表B进行比较,以查找匹配项,但我不知道为什么while循环仅执行一次?
for (WebElement webElement : inputs)
{
if (webElement.getAttribute("type").equalsIgnoreCase("text"))
{
String element = webElement.getAttribute("id").toString();
System.out.println("Element: " + element);
while(e.hasMoreElements())
{
String param = (String) e.nextElement();
System.out.println("Parameter: " + param);
System.out.println(element.matches(param));
if(element.matches(param))
{
webElement.sendKeys(vars.get(param));
//inputs.remove(element);
}
}
}
}
Sorry here is the rest of the code, is referenced before the code above 抱歉,剩下的代码在上面的代码之前被引用
Hashtable vars = new Hashtable();
vars.put("USERNAME","slider");
vars.put("POSTCODE","LU1 3LU");
vars.put("EMAIL","david.cunningham@lumesse.com");
vars.put("DOB","02 Mar 1983");
Enumeration<String> e = vars.keys();
My guess is that you've got something like: 我的猜测是您有类似的东西:
Enumeration e = vector.elements();
outside the for loop. 在for循环之外 。 You need to put it inside the for loop, before the while
loop. 您需要将其放在 while
循环之前的for循环内 。 Otherwise you're iterating all the the way through it, but never going back to the start. 否则,您将一直迭代,但是永远不要重新开始。
(I'd also advise you to use the Iterable
/ Iterator
interfaces if you possibly can, and generic collections.) (如果可能的话,我也建议您使用Iterable
/ Iterator
接口,以及通用集合。)
Based on the code you've shown, the enumeration e
has one element in it. 根据显示的代码,枚举e
包含一个元素。 You haven't shown where e
is created, so nobody will be able to tell you much else. 您尚未显示e
的创建位置,因此没有人可以告诉您更多其他信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.