Categories
Development

Getting error while iterating through list of participants in selenium with wait method

When I debug the program all the 3 participants are selected but when I run it gives error for second participant that

java.lang.IllegalStateException: The Network Member can not be found

Input list has following values

  1. Group Member
  2. Network Member
  3. LD Admin

This is the selector
Xpath for dropdown

  public MessagesPage findRecipient(List userRecipient) throws InterruptedException {


    int userCount = userRecipient.size();
    int index=0;
    for( Object tempUser : userRecipient){
        WebElement rightUser = null;
        SeleniumUtils.waitElementVisible(driver, searchUser);
        searchUser.sendKeys(tempUser.toString());

        //output element of drop down search user name
        By byUserSearchResult = By.xpath("//tbody[@class='js-pages']/tr/td");

        //Wait till the user list is available.
        new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(byUserSearchResult));
        List<WebElement> resultTable = driver.findElements(byUserSearchResult);

        //The code is failing here for 3rd element in the list
        for (WebElement user : resultTable) {
            String check = user.getText();
            if (check.contentEquals(tempUser.toString())) rightUser = user;
        }

        if (rightUser == null)
            throw new IllegalStateException("The " + tempUser.toString() + " can not be found");

        rightUser.click();

    }

Leave a Reply

Your email address will not be published. Required fields are marked *