0

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++){
        if(ResultName.getText().equalsIgnoreCase(globalVariables.NewCorpUserName)){

        }
    }

Need to click on element id avaialble in that row:

//*[@id="CGOLK90700779C"]/span/span/i[3]

ResultName is the position for which variable is stored globally.

enter image description here

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

2 Answers 2

0
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
icon.click();

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));
2
  • 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
0

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++){
        if(ResultName.getText().equalsIgnoreCase(globalVariables.NewCorpUserName)){
            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]";
        driver.findElement(By.xpath(InviteIcon)).click();
        }
        break;
    }

Your Answer

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

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