I have a page in pupeteer in which I'm trying to initiate a file upload and it has to uploading buttons. the problem is both buttons that initiate the file upload have the same type and selector. This working code allows me to upload a file to the first file input perfectly.
input = await mainpage.$('input[type="file"]');
await input.uploadFile(`${__dirname}/images/${photoID}.png`);
await mainpage.waitFor(500);
now my question is - is there a way for me to target the SECOND input of type file on the page in pupeteer programmatically? as they both have the same input type of file selector id etc.. Some sort of index I could do in this same code? I tried all other methods and since the selectors are the same this is the only way I got the first one to work on the page.
Use the page.$$
API to fetch the list of all matching elements. As the docs mention, it returns an array of matching elements and then you should be able to index the array. Somtehing like:
// Get all the elements for the selector
inputs = await mainpage.$$('input[type="file"]');
// Work on individual elements
await input[0].uploadFile(`${__dirname}/images/${photoID}.png`);
...