繁体   English   中英

如何按索引 select 包含在 Playwright(python)中的 iFrame 中的按钮?

[英]How can I select a button contained within an iFrame in Playwright (python) by index?

I am attempting to select a button within an iframe utilizing Python & Playwright... in Selenium I know you can do this by using indexes, is this possible in playwright, I've been digging through the documentation and can't seem to figure出来。 我正在尝试 select 的 iframe 中包含的按钮是:

"button:has-text(\"Add New User\")"

我正在使用的 iframe 的 html 代码与此类似:

<iframe src="https://www.urlthatcannotbereturnedinpagehtml.com/veryparticularparameters" width="100%" style="height: 590px;"></iframe>

有人有想法吗? 大约在这里结束......我试图通过解析网页的代码来找到url,但是不能这样选择这部分。 我可能只是对剧作家的文档感到茫然,我在 selenium 上花了很多时间,这似乎是一种全新的语言。

谢谢!

据我了解,您的页面包含 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();

请注意,该示例使用 iFrame 标记作为定位器,但您可以并且应该使用更准确的标记,例如 ID、名称或 url。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM