1

How to click on element search by text within table. I have tried some code but its not working.

HTML:

<td _ngcontent-c8="" class="align-middle cursorPoint" tabindex="0">Shelton</td>

I want to click on this <tr> which having text Shelton in it.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

1 Answers1

0

The desired element is an Angular element so to locate and click() the element you have to induce WebDriverWait for the element to be clickable and you can use either of the following Locator Strategy:

  • xpath 1:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//td[@class='align-middle cursorPoint' and text()='Shelton']"))).click();
    
  • xpath 2:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//td[text()='Shelton']"))).click();
    

Update

To achieve the same in a step-wise manner:

WebElement elem = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//td[@class='align-middle cursorPoint' and text()='Shelton']")));
elem.click();
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352