A Page refers to a single tab or a popup window within a BrowserContext. You use it to navigate to URLs and interact with page content (e.g., filling inputs, clicking elements).
Key operations:
- Create a page: Use
context.newPage(). - Explicit navigation: Use
page.goto(url) to navigate to a specific URL. - Implicit navigation: Trigger navigation by interacting with elements, such as
page.locator(selector).click(). - Get current URL: Use
page.url() to retrieve the current URL of the page.
// Create a page.
const page = await context.newPage();
// Navigate explicitly
await page.goto('http://example.com');
// Fill an input
await page.locator('#search').fill('query');
// Navigate implicitly by clicking a link
await page.locator('#submit').click();
// Get current url
console.log(page.url());