Lesson 2: Functions and Selectors

Type-Safe Locators

Locators in TS allow you to capture elements with confidence.

Example

typescript

import { Page, Locator } from '@playwright/test';

const button: Locator = page.getByRole('button', { name: 'Submit' });

await button.click();

Locator Chaining

typescript

const product = page.locator('.product-card').filter({ hasText: 'iPhone' });

await product.getByRole('button').click();

    CareerRaah - AI Learning Platform for Professionals