zwappy
zwappy

Reputation: 31

Target an element in an iFrame using Puppeteer

I want to type and get some info from an iframe, within a Site. but my issue is that I cant read any elements within the iFrame. It logs that it loaded the content frame, but cannot target any element after that.

The waitForSelector is "null"

also when I tried to skip the waitForSelector the i get the error message, cannot read property 'type' of null.

await page.waitForSelector("body > div.body.clearfix.container_20 > div.main.grid_12 > iframe");
            // need to target IFRAME

            const frameHandle = await page.$('iframe[class="orderFrame"]');
            const frame = await frameHandle.contentFrame();
            console.log('iFrame load succesfull')

            // paste ORG
            const OrgInput1 = "#Netui_Form_0 > table > tbody > tr:nth-child(4) > td > table > tbody > tr > td > table > tbody > tr:nth-child(3) > td:nth-child(2) > input[type=text]";
            await frame.waitForSelector(OrgInput1);
            await frame.type(OrgInput1, orgNumber, {delay:100});
            // click Next
            await frame.waitFor(2000);

Upvotes: 0

Views: 632

Answers (1)

mbit
mbit

Reputation: 3013

It looks like you can't access the frame content (frame is null). It might be an OOPIF. Try launching chromium/puppeteer with --disable-features=site-per-process.

Upvotes: 1

Related Questions