# How to click a link with a specific text with Puppeteer

> Learn how to click a link or button by its text in Puppeteer using page.$x with an XPath contains() selector, handy for a cookie Accept all button.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2023-05-16 | Topics: [Node.js](https://flaviocopes.com/tags/node/) | Canonical: https://flaviocopes.com/how-to-click-a-link-with-a-specific-text-with-puppeteer/

I wanted to click an “Accept all” cookie button with Puppeteer, I used this code:

```javascript
const [linkcookie] = await page.$x("//a[contains(., 'Accept all')]")
if (linkcookie) {
  await linkcookie.click()
}
```

Note that if the button is a `button` HTML element (it depends on the HTML markup used), you have to use 

```javascript
page.$x("//button[contains(., 'Accept all')]")
```

instead 👍

Also see my full [Puppeteer tutorial](https://flaviocopes.com/puppeteer/)
