最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to find an element inside an iframe in k6browser? - Stack Overflow

programmeradmin1浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论