框架
介绍
🌐 Introduction
一个页面可以附加一个或多个框架对象。每个页面都有一个主框架,并且页面级交互(如click)默认在主框架中操作。
🌐 A Page can have one or more Frame objects attached to it. Each page has a main frame and page-level interactions (like click) are assumed to operate in the main frame.
一个页面可以通过 iframe HTML 标签附加额外的框架。可以访问这些框架以在框架内进行交互。
🌐 A page can have additional frames attached with the iframe HTML tag. These frames can be accessed for interactions inside the frame.
// Locate element inside frame
Locator username = page.frameLocator(".frame-class").getByLabel("User Name");
username.fill("John");
框架对象
🌐 Frame objects
可以使用 Page.frame() API 访问框架对象:
🌐 One can access frame objects using the Page.frame() API:
// Get frame using the frame"s name attribute
Frame frame = page.frame("frame-login");
// Get frame using frame"s URL
Frame frame = page.frameByUrl(Pattern.compile(".*domain.*"));
// Interact with the frame
frame.fill("#username-input", "John");