I'm trying to automate an interaction with a dynamic iframe using K6 Browser, but I'm facing difficulties when trying to click a button inside that iframe. The code I'm using is as follows:
const myFrame = 'iframe[src^="/"][src*="embedded=true"]';
await page.waitForSelector(myFrame, {visible: true, timeout: 1000});
const iframeElement = await page.$(myFrame);
const iframeContent = await iframeElement.contentFrame();
await iframeContent.click('//button[text()="Assinar"]');
console.log(i)
console.log(myFrame)
The iframe URL is dynamic and changes over time, but it follows a pattern where the URL starts with / and contains embedded=true.
I get the following errors:
WARN[0052] Unexpected DevTools server error: context canceled category="ExecutionContext:eval" elapsed="0 ms" source=browser
ERROR[0052] Uncaught (in promise) clicking on "//button[text()=\"Subscribe\"]": timed out after 30s
I tried using waitForSelector
to wait for the iframe, but I still have issues.
Can anyone help me understand how I can handle dynamic iframe URL and click the button correctly inside it? What would be the best approach to do this, considering that the iframe URL is dynamic?