Reputation: 25
How to click on a button with a data-elementid in Puppeteer?
The website has this:
<button class="M-r MB-r j3 Mn-cy" tabindex="0" type="button" data-elementid="searchButton">
I'm trying to click the button:
const selector = '#searchButton';
await page.waitForSelector(selector);
await page.click(selector);
I've tried waiting 10 seconds to make sure the page was fully loaded.
Receiving the error:
TimeoutError: waiting for selector `#searchButton`
Any thoughts?
Upvotes: 1
Views: 316
Reputation: 8322
The problem seems to be in the selector.
This:
const selector = '#searchButton';
translates into this in html:
id="searchButton"
but you're looking for data-elementid="searchButton"
attribute.
Try this instead:
const selector = '[data-elementid="searchButton"]';
Upvotes: 2