首页 > 解决方案 > Puppeteer 没有填写输入元素/错误的选择器?

问题描述

我试图让 puppeteer 自动填写信用卡流程。

该站点的屏幕截图,前 2 个输入字段的 html 代码。(其他字段看起来相同,不同的 id...) 问题是,它没有填写输入字段。它只是无所事事。我的代码:

await page.waitForSelector('#cardpan input[type = text]');
await page.waitForSelector('#cardexpiremonth input[type = text]"]');
await page.waitForSelector('#cardexpireyear input[type = text]');
await page.waitForSelector('#cardcvc2 input[type = text]');

await page.evaluate(() => {

    const ccnumber = document.querySelector('#cardpan input[type = text]');
    ccnumber.value = 'Here comes cc number';
    const month = document.querySelector('#cardexpiremonth input[type = text]"]');
    month.value = '...';
    const year = document.querySelector('#cardexpireyear input[type = text]');
    year.value = '...';
    const cvc = document.querySelector('#cardcvc2 input[type = text]');
    cvc.value = '...';
});

我还尝试了许多不同的其他方法来选择输入元素,但它没有填写该字段。提前感谢您的帮助!:)

标签: htmlcsscss-selectorspuppeteer

解决方案


推荐阅读