How do I click on an element available in a specific row where dynamic row is added?

  • In the below pic, I need to click on the icon in a row which is newly added and column1 value is stored as global variables.

    Have used the below code, unable to find a solution. WebElement userListTable = driver.findElement( By.xpath("//*[@id='KendoActiveCorpUserGrid']/div[2]/table"));

        List<WebElement> rows_table = userListTable.findElements(By.xpath("//*[@id='KendoActiveCorpUserGrid']/div[2]/table/tbody/tr"));
        int rows_count = rows_table.size();
        for (int row = 0; row < rows_count; row++){

    Need to click on element id avaialble in that row:


    ResultName is the position for which variable is stored globally.

    enter image description here

  • for (int row = 0; row < rows_count; row++){
            if(ResultName.getText().equalsIgnoreCase(globalVariables.NewCorpUserName)){ }

    Here, you are just performing the same check (if) rows_count number of times.

    You need to perform the check on each row, rather than on these global variables.

    // Finding the table
    WebElement table = userListTable.findElement(By.xpath("//*[@id='KendoActiveCorpUserGrid']/div[2]/table"));
    waitTargetTextToBeOnTheTable(table, globalVariables.NewCorpUserName);
    //Finding all rows
    List<WebElement> rows = table.findElements(By.cssSelector("tbody tr"));
    // Finding the first row that matches our criterea 
    WebElement targetRow =
                               row -> row.findElement(PLACE_HERE_THE_LOCATOR_OF_THE_USERS_COLUMN).getText().equals(globalVariables.NewCorpUserName).get();
    // Find the icon inside the row
    WebElement icon = row.findElement(By.ByXPath, "//span/span/i[3]");
    // Interact with the icon;

    Replace PLACE_HERE_THE_LOCATOR_OF_THE_USERS_COLUMN with the proper locator, and you will perform the check on each Users column, in order to identify the row.

    waitTargetTextToBeOnTheTable would be as simple as:

    wait.until(ExpectedConditions.textToBePresentInElement(targetElement, targetValue));

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2