Học Playwright tiếng Việt, Cộng đồng Playwright cho người Việt

Vọc Vạch Playwright

[Vọc Playwright] Frame

https://playwright.dev/docs/frames

Giới thiệu

  • Một page có thể có một hoặc nhiều Frame object attach vào.
  • Một page luôn có một main frame để tương tác trực tiếp ở page level (tức là chỉ cần gọi page.{action}), ví dụ page.click.
  • Còn các frame khác thì cần đi đến frame đó trước thì mới tương tác tiếp được (frameLocator):
// Locate element inside frame
const username = await page.frameLocator('.frame-class').getByLabel('User Name');
await username.fill('John');

Frame object

  • Có thể gán frame object vào một biến, dùng cho tiện:
// Get frame using the frame's name attribute
const frame = page.frame('frame-login');

// Get frame using frame's URL
const frame = page.frame({ url: /.*domain.*/ });

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

Trả lời