Locating elements within an iframe

Is there a way to locate an element within an iframe?

I have used page.frame({ url: ‘mysourceurl’ }); within my xk6 test, but Powershell prints out

“Page.frame(frameSelector) has not been implemented yet”

Hey @jbx,

Unfortunately, we don’t support that feature (yet) :frowning: However, you can do something like the following:

import launcher from "k6/x/browser";

export default function () {
  const browser = launcher.launch('chromium', { headless: false })
  const page = browser.newContext().newPage();
  page.setContent(`
    <iframe></iframe>
    <span>outside</span>
  `);

  page.evaluate(() => {
    document.querySelector('iframe').contentDocument.write("<span>inside</span>")
  });

  console.log(page.evaluate(() => {
    return document.querySelector('iframe').contentWindow.document.getElementsByTagName('span')[0].innerText
  }));

  page.close();
  browser.close();
}

When you execute the script using xk6-browser, it should return inside. Please let me know if it helps you.

Awesome! this workaround works fine! glad to bump this! :tada: