开发者

Unexpected result using WebDriver's findelements(By.cssSelector) method in loop

I am using WebDriver to verify elements on a page by css selector. With the following method 'checkTablesByHeader' that I have created.

public static void checkTablesByHeader(WebDriver driver, String[] columnHeaderValues, String tableID, String selector){
    String elementSelector = "#" + tableID + " "+selector; 
    List<WebElement> elements = driver.findElements(By.cssSelector(elementSelector));
    int i = 0;
    for (WebElement e : elements){
        Assert.assertTrue(e.getText().contains(columnHeaderValues[i]));
        i++;
    }

My problem lies with using this method in a loop as seen below. The first pass works perfectly and only grabs nine elements in the List. The second pass should have the same exact number, but is returning 300 + elements. I am doing this because I h开发者_StackOverflow中文版ave tables that have very similar structure, but only different ids. I have checked and rechecked that the id on the second pass can only possibly return 9 elements with the current code.

    for(int i=1; i<6; i++){
    SeleniumUtil.checkTablesByHeader(driver, stringArrayNine, ("mqContent_a_" + i), "th");
    }

Anyone have any ideas? Thank you in advance.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜