【问题标题】:Puppeteer iframe dropdown menu selectPuppeteer iframe 下拉菜单选择
【发布时间】:2019-04-15 13:20:45
【问题描述】:

我正在 puppeteer 中创建一个测试套件,但无法选择 iframe 下拉菜单。

我阅读了文档,运行了几个场景,但似乎无法弄清楚。

try {
    (async () => {
         const browser = await puppeteer.launch({headless: false, 
slowMo: 100});
        const page = await browser.newPage();
        await page.setViewport({ width: 1280, height: 800 });
        await page.goto('https://giving.kcmhq.org/');
        await page.click('.col-sm-12 > .form-group > .radio > 
 .radio-inline > #invoice_items_0_gift_array_0');
        await page.type('.form-group > .form-inline > .col-sm-12 > 
.input-group > #invoice_items_0_other_amount', '9999');
        await page.click('.form-group > .col-sm-8 > div > .btn-other >      #invoice_items_0_is_recurring');
        await page.select('#invoice_items_0 > .fund-inputs-container >     .form-group > .col-xs-3 > 
#invoice_items_0_recurring_withdrawal_day', '15');


 try {
    const frame = await page.frames().find(f => f.name() === 
 'payment_iframe');
    const cardNumber = await frame.$('#card_number');
     await cardNumber.type("444433322221111");

}catch (e) {

}

try {
     const frame = await page.frames().find(f => f.name() === 
'payment_iframe');

    const [response] = await Promise.all([

            frame.select('#card_expiration_month', 'March'),


     ]);

}catch (e) {

}  

信用卡示例的 iframe 有效,但“car_expiration_month”下拉菜单和选择月份的 iframe 无效。

【问题讨论】:

    标签: javascript puppeteer end-to-end


    【解决方案1】:

    查看页面的每一帧可能会对您有所帮助:

    for (const frame of page.mainFrame().childFrames()){
        // Here you can use few identifying methods like url(),name(),title()
        if (frame.url().includes('twitter')){
            console.log('we found the Twitter iframe')
            twitterFrame = frame 
            // we assign this frame to myFrame to use it later
        }
    }
    

    信用:https://kb.apify.com/articles/2116540-scraping-iframes-with-puppeteer

    【讨论】:

      猜你喜欢
      • 2021-06-09
      • 2019-05-01
      • 2020-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-28
      • 2023-03-31
      • 1970-01-01
      相关资源
      最近更新 更多