Usando titiritero estoy tratando de lograr algo donde puedo capturar las respuestas de la red en la selección de un elemento desplegable. No tiene que ser inmediato, podemos seleccionar todas las opciones una tras otra, y también podemos usar la respuesta de red más tarde, siempre que funcione sin problemas.
(async () => { const browser = await puppeteer.launch(chromeoptions); const page = await browser.newPage(); page.target().createCDPSession(); page.setDefaultNavigationTimeout(1000000); } async function getAppointmentData() { await page.goto('go to the page URL') let appointmentData = []; await page.waitForSelector( "[id*=dropdownId]" ); for (let option of options) { // Selecting an option from a dropdown trigger a network call that I need to record await page.select( "select#dropdownId", option?.id ) /* Check for a network call that contains that option?.id or .json?details Sample URL >>>> https://abc.test.com/en/10.json?details [Where 10 is options?id] */ // After All Items in dropdown is selected, Want to insert response [Array of Objects] to an object like: appointmentData.push({ id: options?.id; data: [Array of Objects] }] } // For Loop Ends processAppointments(appointmentData ) } processAppointments(data) { /// } getAppointmentData(); })(); Intenté usar page.on() y otros métodos, pero no fue útil. ¿Puede alguien por favor ayudarme aquí? estado atrapado durante casi una semana.
Su page.on debería verse algo como:
page.on("response", response => { let match = response.url().match(/(\d+).json/) if(match){ console.log(`option ${match[1]}`) } })