I am trying to scrape a dynamic site using puppeteer in node, but not able to click the required elements no matter what. Please help!
JavaScript
x
14
14
1
// this script parses the data from https://excise.wb.gov.in/CHMS/Public/Page/CHMS_Public_Hospital_Bed_Availability.aspx
2
const puppeteer = require('puppeteer');
3
4
(async function scrape() {
5
const browser = await puppeteer.launch({headless: false});
6
const page = await browser.newPage();
7
// page.setDefaultNavigationTimeout(90000);
8
const url = "https://excise.wb.gov.in/CHMS/Public/Page/CHMS_Public_Hospital_Bed_Availability.aspx";
9
await page.goto(url, {waitUntil: 'networkidle2', timeout: 0});
10
// await page.waitForNavigation({ waitUntil: 'networkidle2' })
11
await page.waitForSelector('#ctl00_ContentPlaceHolder1_ddl_District');
12
await page.click('#ctl00_ContentPlaceHolder1_ddl_District');
13
})();
14
Tried this too, but no luck:
JavaScript
1
5
1
const selectButt = await page.evaluateHandle(() =>
2
document.querySelector('#ctl00_ContentPlaceHolder1_ddl_District')
3
);
4
await selectButt.click();
5
Advertisement
Answer
It’s a <select>
, you probably don’t want to click on it, but choose an option instead:
JavaScript
1
2
1
await page.select('#ctl00_ContentPlaceHolder1_ddl_District', '020'); // ALIPURDUAR
2
Triggers a
change
andinput
event once all the provided options have been selected.