Have issue when have several button in <td>

Hello, i have issue in handle web table, there is 3 button in and i want to click edit button.


in my script i use handle web table script to search username (ExpectedUsername) and i want to click in edit button.

String ExpectedUsername = GlobalVariable.user_username
WebDriver driver = DriverFactory.getWebDriver()
WebElement Table = driver.findElement(By.xpath(“//[@id=‘kt_content’]/div[2]/div/div/div[2]/div[1]/table/tbody”))
List Rows = Table.findElements(By.tagName(‘tr’))
table: for (int i = 0; i < Rows.size(); i++) {
List Cols = Rows.get(i).findElements(By.tagName(‘td’))
for (int j = 0; j < Cols.size(); j++) {
if (Cols.get(j).getText().equalsIgnoreCase(ExpectedUsername)) {
Cols.get(7).findElement(By.xpath(“What should i write here”)).click()
break table

and here is script

please help, thanks

without seeing the page html, i can’t offer a better solution, but i’ll be working under the assumption those are buttons
you can either use the position of the button(the second button) with xpath “.//button[2]”
or, as a better solution, use xpath to select the button that has a descendant with the edit icon in it, i don’t know which icon is used out of my head, and how that button knows what icon to use
but, in short, something like xpath ".//button[descendant::i[contains(@class, ‘fa-pencil’)]]

As kenzie.rigole says, without HTML we are not able to help much, but you might be able to use something.

Personally, you have it correct except the one statement:
Cols.get(7).findElement(By.xpath(“What should i write here”)).click()
You should change this to:

Now, if column 8 is a column with three buttons, then you can try to do another findElements to get all three buttons and then click on the second button, Butts.get(1).click(); or see if you can do an array of the previous statement: Cols.get(7)[1].click();

However, if each of the buttons is in their own column, then you would be good to go with the fixed statement I have at top.