kre*_*034 4 python iframe playwright
我正在尝试使用 Python 和 Playwright 在 iframe 中选择一个按钮...在 Selenium 中我知道你可以通过使用索引来做到这一点,这在 playwright 中是否可能,我一直在挖掘文档,但似乎无法弄清楚出来。我尝试选择的 iframe 中包含的按钮是:
"button:has-text(\"Add New User\")"
Run Code Online (Sandbox Code Playgroud)
我正在使用的 iframe 的 html 代码类似于以下内容:
<iframe src="https://www.urlthatcannotbereturnedinpagehtml.com/veryparticularparameters" width="100%" style="height: 590px;"></iframe>
Run Code Online (Sandbox Code Playgroud)
有人有想法吗?关于这里束手无策......我试图通过解析网页的代码来找到url,但是这部分不能像那样选择。我可能只是对剧作家的文档感到不知所措,我在硒上花了很多时间,这似乎是一种全新的语言。
谢谢!
小智 7
据我了解,您的页面在 iframe 中包含内容。您想要使用 Playwright 访问该框架内的元素。
处理帧的官方文档: 官方文档:https://playwright.dev/docs/frames#frame-objects
然后你可以尝试这样的事情:
// Locate element inside frame
const iframeButton = await page.frameLocator('iFrame').locator("button:has-text(\"Add New User\")");
await iframeButton.click();
Run Code Online (Sandbox Code Playgroud)
请注意,该示例使用 iFrame 标记作为定位器,但您可以并且应该使用更准确的内容,例如 id、名称或 url。