跳至主要内容

框架

简介

一个Page可以附加一个或多个Frame对象。每个页面都有一个主框架,页面级别的交互(如click)默认在主框架中操作。

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
# Get frame using any other selector
username = page.frame_locator('.frame-class').get_by_label('User Name')
username.fill('John')

Frame对象

可以使用page.frame() API访问框架对象:

# Get frame using the frame's name attribute
frame = page.frame('frame-login')

# Get frame using frame's URL
frame = page.frame(url=r'.*domain.*')

# Interact with the frame
frame.fill('#username-input', 'John')