Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html selector using Regex

Tags:

html

puppeteer

So there is a page that I want to perform some action on with puppeteer. The problem is that there is a text area in which I want to type in something however the id of it is :

id="pin-draft-title-13a10e18-5a1e-49b9-893c-c5e028dc63e1"

As you might have guess for some reason only pin-draft-title remains the same but the whole number part changes for every refresh so puppeteer can't find it. I tried deleting the id and copying the selector itself the whoe #_Root div>div etc but that seems to be changing after sometime as well. So the main question is is there any way i can just select it using the pin-draft-title part and no matter what numbers follow it still selects it ?

like image 435
Hadi Pawar Avatar asked May 23 '26 10:05

Hadi Pawar


1 Answers

In case of javascript, if you want to select all the elements whos ID starts with a specified string or pattern, in your case "pin-draft-title", then consider using the following syntax.

document.querySelectorAll('[id^="pin-draft-title"]');
like image 166
Adil Ahmed Avatar answered May 26 '26 05:05

Adil Ahmed