随时随地阅读更多技术实战干货,获取项目源码、学习资料,请关注源代码社区公众号(ydmsq666)
from:https://github.com/GoogleChrome/puppeteer/issues/684
对于这个问题issues还有其它的处理方式,我用MaxProvin的方式解决了我的问题
The best workaround for trying to directly click an element inside an iframe that i've found is to simply select the frame containing the element and then use the frame methods to navigate/select elements inside the frame.
e.g.
const selector = '#elementId';
const Frame = await page.frames()[1]; // quick and dirty selection of the frame i'm after, serves for example though...
await Frame.$eval(selector, el => el.click());