Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

363
Vistas
Target an iFrame using Node.js/Puppeteer

Is it possible to target an iFrame when using the GUI Workflow builder in AWS Cloudwatch Synthetics?

I've set up the canary to log in to a website and redirect the page which has run successfully, but one of the elements I need to check with Node.js is within an iFrame which isn't being recognised.

This is the iframe code. It loads from Javascript, but all content is from the same domain:

<iframe id="paramsFrame" src="empty.htm" frameborder="0" ppTabId="-1"
                    onload="paramsDocumentLoaded('paramsFrame', true);"></iframe>

This is the code I'm using for this section, but it's just returning a timeout error:

   await synthetics.executeStep('verifyText', async function() {
    const elementHandle = await page.waitForSelector('#paramsFrame');
    const frame = await elementHandle.contentFrame();
    await frame.waitForXPath("//div[@class=\'css7\'][contains(text(),'Specificity')]", { timeout: 30000 });
})

This code is trying to target a div with class css7 found within an iframe with id paramsFrame

Edit: I did a null check on frame and it came back as not null, not sure if that is relevant.

I also tried to target an element directly:

const next = await frame.waitForSelector('.protocol-name-link');

but I got the error message:

TimeoutError: waiting for selector .protocol-name-link

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

If the iframe is on a different origin (e.g. different domain), you cannot access it through Puppeteer.

You can try to disable some security features of Puppeteer, although this is not advised.

Specifically, you'd probably want to add these args to puppeteer.launch

 --disable-web-security
 --disable-features=IsolateOrigins,site-per-process
about 4 years ago · Juan Pablo Isaza Denunciar

0

I tried running similar code on a website which had a youtube iframe and I didnt need the puppeteer launch args

i.e

args: [
  "--disable-web-security",
  "--disable-features=IsolateOrigins,site-per-process",
],

But, First I would like to suggest is for the iframe try to confirm it is the same iframe that you need maybe by logging, debugging or even just going on dev console.

And the second is to use full xpath of the element in the frame.

Here is my code which I tried running.

  const page = await browser.newPage();
  console.log("open page");

  await page.goto("https://captioncrusher.com/");
  console.log("page opened");

  // use this if you want to wait for all the requests to be done.
  // await page.waitForNetworkIdle();

  const elementHandle = await page.waitForSelector("iframe.yt");
  const frame = await elementHandle.contentFrame();

  //These both work for me
  const aLink = await frame.waitForXPath("/html/body/div/div/a");
  const classLink = await frame.waitForSelector(".ytp-impression-link");
 
  await browser.close();
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda