程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了无法在 Puppeteer 中访问 iframe 中的元素大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决无法在 Puppeteer 中访问 iframe 中的元素?

开发过程中遇到无法在 Puppeteer 中访问 iframe 中的元素的问题如何解决?下面主要结合日常开发的经验,给出你关于无法在 Puppeteer 中访问 iframe 中的元素的解决方法建议,希望对你解决无法在 Puppeteer 中访问 iframe 中的元素有所启发或帮助;
 await page.iSELER_592_11845@entVisible('iframe');
    console.log('iframe is ready. Loading iframe content');
    const elementHandle = await page.waitForSELEctor("iframe[ID='payment-form']");
    const frame = await elementHandle.contentFrame();

它一直工作到这一点

    // console.log('filling form in iframe');       
    
    const cardType = await frame.$x(`//div[contains(@class,'css-12kbcej')]//SELEct[@data-elID="card-type"]`);
    await page.click();
    

也尝试这样做

 await page.waitForXPathAndClick(`//div[contains(@class,'css-12kbcej')]//SELEct[@data-elID="card-type"]`);

还有这个

    const cardType = await frame.$x(`//div[contains(@class,'css-12kbcej')]//SELEct[@data-elID="card-type"]`);
    await frame.click(cardTypE);

但没有任何效果

错误信息

错误:评估失败:DOMException:无法在“文档”上执行“querySELEctor”:提供的选择器为空。 在 puppeteer_evaluation_script:1:33

解决方法

您有 await page.click(); -- page.click() 需要一个选择器,例如 page.click('myCssSELEctor')。这就是您收到该错误的原因,The provided SELEctor is empty

大佬总结

以上是大佬教程为你收集整理的无法在 Puppeteer 中访问 iframe 中的元素全部内容,希望文章能够帮你解决无法在 Puppeteer 中访问 iframe 中的元素所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。