To retrieve the input value in @playwright/test, you can use the inputValue()
method on a locator object. First, you need to create a locator for the input element using the page.locator()
method. Then, call the inputValue()
method on the locator to get the input value.
Here's an example:
import { test, expect } from '@playwright/test';
test('Get input value', async ({ page }) => {
await page.goto('https://ray.run/');
// Locate the input element
const inputLocator = page.locator('input[type="text"]');
// Set a value for the input element
await inputLocator.fill('Hello, Playwright!');
// Get the input value
const inputValue = await inputLocator.inputValue();
// Check if the input value is correct
expect(inputValue).toBe('Hello, Playwright!');
});
In this example, we navigate to the https://ray.run/
website, locate an input element of type "text", fill it with the text "Hello, Playwright!", and then retrieve the input value using the inputValue()
method. Finally, we use the expect()
function to check if the retrieved value matches the expected value.
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].