如何通过索引选择Playwright(python)中iFrame中包含的按钮



我正试图使用Python&剧作家在Selenium中,我知道你可以通过使用索引来做到这一点,在player中这可能吗?我一直在翻阅文档,似乎无法弄清楚。我试图选择的iframe中包含的按钮是:

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

我使用的iframe的html代码看起来类似于:

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

有人有什么想法吗?无计可施。。。。我试图通过解析网页的代码来找到url,但这部分不能像那样选择。我可能只是对剧作家的文档感到不知所措,我在硒方面花了太多时间,这似乎是一种全新的语言。

谢谢!

据我所知,您有一个在iframe中包含内容的页面。您希望使用Playwright访问该帧中的元素。

处理框架的官方文档:官方文档:https://playwright.dev/docs/frames#frame-对象

然后你可以试试这样的东西:

// Locate element inside frame
const iframeButton = await page.frameLocator('iFrame').locator("button:has-text("Add New User")");
await iframeButton.click();

请注意,该示例使用iFrame标记作为定位器,但您可以也应该使用更准确的标记,如and-id、name或url。

最新更新