const [button] = await page.$x("//button[contains(., 'Button text')]"); if (button) { await button.click(); }