tniles320
tniles320

Reputation: 33

Puppeteer select element id where beginning and end are dynamically generated

I'm trying to use puppeteer to select a dynamic element id. I've found how to select and element using just the beginning or just the end, but what I'm currently trying to do is find the element by the static part of the id in the center.

await page.waitForSelector('[id^="holder"][id$="_private_1"]');

In the above code snippet the original id looks like holder123456_private_1. I've gotten that part fine. However, the end of "_private_1" the number may change. So essentially I need the same code above but leave off the number at the end.

Upvotes: 2

Views: 1565

Answers (1)

mbehzad
mbehzad

Reputation: 3878

What you probably could do is to use '[id^="holder"][id*="_private_"]' as your selector (id starts with "holder" and has "_private_" somewhere in the id name. That would work if you don't have elements with e.g. id="holder123_not_private_321" which you don't want to target. Otherwise i don't think there is any other selector options (https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors)

Upvotes: 1

Related Questions