簡體   English   中英

Puppeteer iframe下拉菜單選擇

[英]Puppeteer iframe dropdown menu select

我在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和選擇月份不起作用。

查看頁面的每一幀可能對您有所幫助:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM