0

I work on a test automation project on an automotive site, for that I use JavaScript as a programming language with the two Playwright and Cucumber frameworks. So when I did my test I got to a test where I have to manipulate the iframes so I can't access this iframe to click on the button inside and to write on the text fields! I tried a lot of methods among them:

/*`module. exports = async function switchToIframe(page, iframeLocator) { const iframeElement = await page.locator(iframeLocator); const iframe = await iframeElement.frame();

 return iframe;

}`*/

but I would still get the error:

/TypeError: Cannot read properties of undefined (reading 'Locator') or frameLocator, ........../

So I would like your help if someone can explain to me how to manipulate iframes with playwright and cucumber?

/*`module. exports = async function switchToIframe(page, iframeLocator) { const iframeElement = await page.locator(iframeLocator); const iframe = await iframeElement.frame();

 return iframe;

}`*/

/TypeError: Cannot read properties of undefined (reading 'Locator') or frameLocator, ........../

1 Answers1

0

as far as I understood your query. you would like to access the iframe. you can simply use the below code

const elementHandle = await page.$(
      // your iframe locator
    );
const frame = await elementHandle.contentFrame();

check this for more: https://playwright.dev/docs/api/class-framelocator#frame-locator-frame-locator

or in advanced playwright versions, you could use frameLocator

await page
      .frameLocator(<iframlocator>)
      .first()
      .locator(<inside-iframe-locator>)
tushi43
  • 60
  • 1
  • 6