The Page object in Playwright is your key to interacting with a web page. It's like a remote control, allowing you to navigate to URLs, click elements, fill out forms, and more.
First, launch a browser instance:
const browser = await browserType.launch();
Then, create a new context:
const context = await browser.newContext();
Finally, create a new page:
const page = await context.newPage();
You can navigate to a URL with page.goto(url). For example:
await page.goto('https://ray.run/');
Take a screenshot using page.screenshot(options). Here's how:
await page.screenshot({ path: 'example.png' });
Click elements with page.click(selector), fill out forms with page.fill(selector,value), and evaluate JavaScript with page.evaluate(pageFunction,...args).
The Page object emits events like load and request. You can handle these with Node's EventEmitter methods like on(), once(), or removeListener().
In short, the Page object is your best friend for programmatically interacting with web pages in Playwright. Happy testing!
If you still have questions, please ask a question and I will try to answer it.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.