我有一个小问题,我找不到使用 Microsoft Playwright 框架的答案。根据文档( https://playwright.dev/#version=v1.1.1&path=docs%2Fcore-concepts.md&q=pages-and-frames ),您可以使用以下代码获取 iframe
const frame = page.frame('frame-login');
但是如何使用选择器来查找和交互 iframe?我需要使用 css-selector 来查找我的 iframe,因为它没有 id。
任何帮助表示赞赏
最佳答案
您可以使用 elementHandle.contentFrame()
await page.waitForSelector('.class-name')
const elementHandle = await page.$('.class-name')
const frame = await elementHandle.contentFrame()
从那一刻起,您可以与 <iframe>
的内容进行交互。喜欢:await frame.<method_name>
.
关于javascript - 如何使用选择器使用 Playwright 查找框架(iframe),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62596046/