Reputation: 1
I'm using headless chrome with nodejs puppeteer library mostly. I'm having trouble selecting or clicking any options in a drop down. The problem is all the IDs are dynamic and change with every click. I've tried scraping the HTML and searching for the current id, but to no avail.
Is there another way to select an option? Is it possible to use a different selector besides id?
note for image: where it says 'homeState-aria-id-7' the number 7 is dynamically generated
Upvotes: 0
Views: 1563
Reputation: 259
I'm not sure I am completely following the reason that having a dynamically created ID would cause issues. Here is an example with how I have solved the problem and using a selector for your code above.
page.evaluate(optionSelector => {
return document.querySelector(optionSelector).setAttribute('selected, 'true');
}, 'select[name="homeState"] > option[value="AL"]');
Upvotes: 1