Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use this Datepicker with Puppeteer

I would like to crawl flight data from the following page: https://www.airprishtina.com/de/

I managed to select the airports, but this page has a Datepicker and I don't get it how to use it programmatically. With a Click on the Startdate Input i can open the Datepicker,

await page.click('#txt_FromDateText');

But what do I need to do to select the date/date range ? I tried to wait for a day selector and click One, but this does not work.

const daySelector = '.available.flight-present';
await page.waitForSelector(daySelector);   
const elements = await page.$('.available');
const el = Array.from(elements).filter(el => {
    return el.dataset.usrDate === '2019-10-26';
})[0];
console.log(el);
await el.click();

console.log ist printing the element, but it does not get selected in the datepicker. What am I doing wrong?

Thanks for any hints.

like image 586
Simon Hansen Avatar asked Oct 28 '25 17:10

Simon Hansen


1 Answers

the solution is to remove the readonly attribute from the #txt_FromDateText element.

await page.focus('#txt_FromDateText');
await page.$eval('#txt_FromDateText',(e) => e.removeAttribute("readonly"));

Then you can enter any date with "await page.type".

:)

like image 154
Fritz Sierra Tintaya Avatar answered Oct 31 '25 08:10

Fritz Sierra Tintaya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!