In version 1.17, Playwright introduced frame locators, which simplify working with iframes. You can now locate elements within iframes using the frameLocator
method:
import { test } from '@playwright/test';
test('Frame locators example', async ({ page }) => {
await page.goto('https://ray.run/');
const frameLocator = page.locator('iframe').first();
await frameLocator.locator('button').click();
});
The new getByTitle
method allows you to locate elements by their title attribute:
import { test } from '@playwright/test';
test('getByTitle example', async ({ page }) => {
await page.goto('https://ray.run/');
await page.getByTitle('Submit').click();
});
Playwright 1.17 enhances locators by providing better error messages and improving the screenshot functionality. You can now take screenshots of specific elements using locators:
import { test } from '@playwright/test';
test('Screenshot example', async ({ page }) => {
await page.goto('https://ray.run/');
const buttonLocator = page.locator('button');
await buttonLocator.screenshot({ path: 'button.png' });
});
Playwright Codegen now generates locators and frame locators, making it easier to work with iframes and elements in your tests.
A potentially breaking change affects users who previously configured tests using environment variables. Make sure to update your configuration accordingly.
For more information on Playwright updates and best practices, check out Ray.run's blog.
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 [email protected].