简体   繁体   English

剧作家 - 如何切换到新标签,然后切换到框架

[英]Playwright - how to switch to new tab and then to frame

I have below scenario -我有以下情况 -

  1. Launch browser and do some operations启动浏览器并进行一些操作
  2. Click on a button, a new tab opens单击一个按钮,将打开一个新选项卡
  3. switch to new tab.切换到新标签。
  4. In new tab, switch to iframe and perform operations inside frame.在新选项卡中,切换到 iframe 并在框架内执行操作。

How can I handle this in playwright?我如何在剧作家中处理这个问题? Once I switch to new tab, all elements are inside frame, so I want to switch to new frame after switching to new tab一旦我切换到新标签,所有元素都在框架内,所以我想在切换到新标签后切换到新框架

Note - Frame doesn't have name.注意 - 框架没有名称。 I can use xpath to identify frame.我可以使用 xpath 来识别框架。

will page.frame("xpath to iframe") work? page.frame("xpath to iframe") 会工作吗?

If anyone can provide small code snippet, would be really helpful.如果有人可以提供小代码片段,那将非常有帮助。

I Tried using page.frame("xpath locator to iframe") - but not working我尝试使用 page.frame("xpath locator to iframe") - 但不工作

You can switch to the new tab like this .您可以像这样切换到新标签。

const [newTab] = await Promise.all([
  page.waitForEvent('popup'),
  page.locator('#open').click(),
]);

await newTab.waitForLoadState();

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

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