使用等待方法遍历硒参与者列表时出错

问题描述 投票:0回答:1

当我调试程序时,所有3个参与者都被选中,但是当我运行该程序时,第二个参与者就会出错

java.lang.IllegalStateException:找不到网络成员

输入列表具有以下值

  1. 小组成员
  2. 网络成员
  3. LD管理员

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();

    }
java selenium selenium-webdriver webdriverwait
1个回答
0
投票

您需要为每个项目诱使Webdriver等待(elementToBeClickable)。在您的代码中,您需要在rightUser.click();

之前使用它
© www.soinside.com 2019 - 2024. All rights reserved.