Search code examples
c#xpathpuppeteerpuppeteer-sharp

Puppeteer Find TR with TD That Has Specific Content


I am attempting to click on a row that has a td in in with a specific string in it.

I have attempted this and a few other options:

await page.ClickAsync(".//td[contains(., 'ABC-DEF-GHI')]");

But i get the error:

Evaluation failed: DOMException: Failed to execute 'querySelector' on 'Document': './/td[contains(., 'ABC-DEF-GHI')]' is not a valid selector.

This is what it looks like in a browser:

enter image description here

Can anyone offer me any advice please?


Solution

  • To use XPath based and not CSS selection use page.XPathAsync(xpath-expression) e.g.

    var tds = page.XPathAsync(".//td[contains(., 'ABC-DEF-GHI')]");
    await tds[0].ClickAsync();