メインコンテンツへスキップ

フレーム

はじめに

1つ以上のページに、1つ以上のフレームオブジェクトをアタッチできます。各ページにはメインフレームがあり、ページレベルのインタラクション (clickなど) はメインフレームで操作されると想定されます。

ページには、iframe HTMLタグで追加のフレームをアタッチできます。これらのフレームは、フレーム内のインタラクションのためにアクセスできます。

// Locate element inside frame
var username = await page.FrameLocator(".frame-class").GetByLabel("User Name");
await username.FillAsync("John");

フレームオブジェクト

Page.Frame() API を使用してフレームオブジェクトにアクセスできます。

// Create a page.
var page = await context.NewPageAsync();

// Get frame using the frame's name attribute
var frame = page.Frame("frame-login");

// Get frame using frame's URL
var frame = page.FrameByUrl("*domain.");

// Get frame using any other selector
var frameElementHandle = await page.EvaluateAsync("window.frames[1]");
var frame = await frameElementHandle.ContentFrameAsync();

// Interact with the frame
await frame.FillAsync("#username-input", "John");