1

I'm using Puppeteer with Jest and I'm trying to get the iframe element using this function:

const frame = await page
  .frames()
  .find(f => f.name() === 'iframe-class');

The problem is: is there a way to get the iframe by his class instead of the name attribute?

I do not have access to this iframe to insert a new attribute, so I need to select by the class.

hardkoded
  • 18,915
  • 3
  • 52
  • 64
Victor
  • 724
  • 3
  • 12
  • 32

2 Answers2

4

You can use the contentFrame function.

const elementHandle = await page.$('.iframe-class');
const frame = await elementHandle.contentFrame();
hardkoded
  • 18,915
  • 3
  • 52
  • 64
-1

Consider using a document query selector to find your <iframe class="external-data">:

document.querySelectorAll('.external-data');
Justin
  • 485
  • 5
  • 13