开发者

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?

for (WebElement we开发者_如何学JAVAbElement : 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. You need to put it inside the for loop, before the while loop. 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.)


Based on the code you've shown, the enumeration e has one element in it. You haven't shown where e is created, so nobody will be able to tell you much else.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜