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

  • Is the problem that the test doesn't wait for the element to appear? Jul 15, 2019 at 18:34

2 Answers 2

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 = rows.stream().findFirst(
                           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));
  • By.ID, "CGOLK90700779C" wont work on 2nd run, CGOLK90700779C is dynamic. Thnks!
    – RK007
    Jul 16, 2019 at 4:59
  • Could you share a HTML snippet of the <table> node (and its sub-nodes)? Jul 16, 2019 at 6:55

Thanks for all your answer and valuable feedbacks!

I finally found solution putting elementid.gettext() inside xpath. It worked fine.

for (int row = 0; row <=rows_count; row++){
            Log.message("Corp User present in the list and Name found as: "+ResultName.getText());
            String InviteIcon = "//td[contains(text(),'"+ResultName.getText()+"')]/../td[8]/div[2]//span//i[3]";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.