Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

feat(api): shorted getByLabel, getByPlaceholder (#17816)

Pavel Feldman8810b55504f7
diff --git a/docs/src/api/class-frame.md b/docs/src/api/class-frame.md
index 15253566da..c237022eea 100644
--- a/docs/src/api/class-frame.md
+++ b/docs/src/api/class-frame.md
@@ -918,24 +918,24 @@ Attribute name to get the value for.
### option: Frame.getByAltText.exact = %%-locator-get-by-text-exact-%%
-## method: Frame.getByLabelText
+## method: Frame.getByLabel
* since: v1.27
- returns: <[Locator]>
%%-template-locator-get-by-label-text-%%
-### param: Frame.getByLabelText.text = %%-locator-get-by-text-text-%%
-### option: Frame.getByLabelText.exact = %%-locator-get-by-text-exact-%%
+### param: Frame.getByLabel.text = %%-locator-get-by-text-text-%%
+### option: Frame.getByLabel.exact = %%-locator-get-by-text-exact-%%
-## method: Frame.getByPlaceholderText
+## method: Frame.getByPlaceholder
* since: v1.27
- returns: <[Locator]>
%%-template-locator-get-by-placeholder-text-%%
-### param: Frame.getByPlaceholderText.text = %%-locator-get-by-text-text-%%
-### option: Frame.getByPlaceholderText.exact = %%-locator-get-by-text-exact-%%
+### param: Frame.getByPlaceholder.text = %%-locator-get-by-text-text-%%
+### option: Frame.getByPlaceholder.exact = %%-locator-get-by-text-exact-%%
## method: Frame.getByRole
diff --git a/docs/src/api/class-framelocator.md b/docs/src/api/class-framelocator.md
index a10097bbbc..cdf0ade996 100644
--- a/docs/src/api/class-framelocator.md
+++ b/docs/src/api/class-framelocator.md
@@ -124,24 +124,24 @@ in that iframe.
### option: FrameLocator.getByAltText.exact = %%-locator-get-by-text-exact-%%
-## method: FrameLocator.getByLabelText
+## method: FrameLocator.getByLabel
* since: v1.27
- returns: <[Locator]>
%%-template-locator-get-by-label-text-%%
-### param: FrameLocator.getByLabelText.text = %%-locator-get-by-text-text-%%
-### option: FrameLocator.getByLabelText.exact = %%-locator-get-by-text-exact-%%
+### param: FrameLocator.getByLabel.text = %%-locator-get-by-text-text-%%
+### option: FrameLocator.getByLabel.exact = %%-locator-get-by-text-exact-%%
-## method: FrameLocator.getByPlaceholderText
+## method: FrameLocator.getByPlaceholder
* since: v1.27
- returns: <[Locator]>
%%-template-locator-get-by-placeholder-text-%%
-### param: FrameLocator.getByPlaceholderText.text = %%-locator-get-by-text-text-%%
-### option: FrameLocator.getByPlaceholderText.exact = %%-locator-get-by-text-exact-%%
+### param: FrameLocator.getByPlaceholder.text = %%-locator-get-by-text-text-%%
+### option: FrameLocator.getByPlaceholder.exact = %%-locator-get-by-text-exact-%%
## method: FrameLocator.getByRole
diff --git a/docs/src/api/class-locator.md b/docs/src/api/class-locator.md
index 24b9d8efde..72308eb2a7 100644
--- a/docs/src/api/class-locator.md
+++ b/docs/src/api/class-locator.md
@@ -644,24 +644,24 @@ Attribute name to get the value for.
### option: Locator.getByAltText.exact = %%-locator-get-by-text-exact-%%
-## method: Locator.getByLabelText
+## method: Locator.getByLabel
* since: v1.27
- returns: <[Locator]>
%%-template-locator-get-by-label-text-%%
-### param: Locator.getByLabelText.text = %%-locator-get-by-text-text-%%
-### option: Locator.getByLabelText.exact = %%-locator-get-by-text-exact-%%
+### param: Locator.getByLabel.text = %%-locator-get-by-text-text-%%
+### option: Locator.getByLabel.exact = %%-locator-get-by-text-exact-%%
-## method: Locator.getByPlaceholderText
+## method: Locator.getByPlaceholder
* since: v1.27
- returns: <[Locator]>
%%-template-locator-get-by-placeholder-text-%%
-### param: Locator.getByPlaceholderText.text = %%-locator-get-by-text-text-%%
-### option: Locator.getByPlaceholderText.exact = %%-locator-get-by-text-exact-%%
+### param: Locator.getByPlaceholder.text = %%-locator-get-by-text-text-%%
+### option: Locator.getByPlaceholder.exact = %%-locator-get-by-text-exact-%%
## method: Locator.getByRole
@@ -1128,31 +1128,31 @@ await element.TypeAsync("World", new() { Delay = 100 }); // Types slower, like a
An example of typing into a text field and then submitting the form:
```js
-const element = page.getByLabelText('Password');
+const element = page.getByLabel('Password');
await element.type('my password');
await element.press('Enter');
```
```java
-Locator element = page.getByLabelText("Password");
+Locator element = page.getByLabel("Password");
element.type("my password");
element.press("Enter");
```
```python async
-element = page.get_by_label_text("Password")
+element = page.get_by_label("Password")
await element.type("my password")
await element.press("Enter")
```
```python sync
-element = page.get_by_label_text("Password")
+element = page.get_by_label("Password")
element.type("my password")
element.press("Enter")
```
```csharp
-var element = page.GetByLabelText("Password");
+var element = page.GetByLabel("Password");
await element.TypeAsync("my password");
await element.PressAsync("Enter");
```
diff --git a/docs/src/api/class-locatorassertions.md b/docs/src/api/class-locatorassertions.md
index f12eb6c498..ee1835273e 100644
--- a/docs/src/api/class-locatorassertions.md
+++ b/docs/src/api/class-locatorassertions.md
@@ -404,30 +404,30 @@ Expected options currently selected.
Ensures the [Locator] points to a checked input.
```js
-const locator = page.getByLabelText('Subscribe to newsletter');
+const locator = page.getByLabel('Subscribe to newsletter');
await expect(locator).toBeChecked();
```
```java
-assertThat(page.getByLabelText("Subscribe to newsletter")).isChecked();
+assertThat(page.getByLabel("Subscribe to newsletter")).isChecked();
```
```python async
from playwright.async_api import expect
-locator = page.get_by_label_text("Subscribe to newsletter")
+locator = page.get_by_label("Subscribe to newsletter")
await expect(locator).to_be_checked()
```
```python sync
from playwright.sync_api import expect
-locator = page.get_by_label_text("Subscribe to newsletter")
+locator = page.get_by_label("Subscribe to newsletter")
expect(locator).to_be_checked()
```
```csharp
-var locator = Page.GetByLabelText("Subscribe to newsletter");
+var locator = Page.GetByLabel("Subscribe to newsletter");
await Expect(locator).ToBeCheckedAsync();
```
diff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.md
index dc609c4738..9fb1e5cddf 100644
--- a/docs/src/api/class-page.md
+++ b/docs/src/api/class-page.md
@@ -2193,24 +2193,24 @@ Attribute name to get the value for.
### option: Page.getByAltText.exact = %%-locator-get-by-text-exact-%%
-## method: Page.getByLabelText
+## method: Page.getByLabel
* since: v1.27
- returns: <[Locator]>
%%-template-locator-get-by-label-text-%%
-### param: Page.getByLabelText.text = %%-locator-get-by-text-text-%%
-### option: Page.getByLabelText.exact = %%-locator-get-by-text-exact-%%
+### param: Page.getByLabel.text = %%-locator-get-by-text-text-%%
+### option: Page.getByLabel.exact = %%-locator-get-by-text-exact-%%
-## method: Page.getByPlaceholderText
+## method: Page.getByPlaceholder
* since: v1.27
- returns: <[Locator]>
%%-template-locator-get-by-placeholder-text-%%
-### param: Page.getByPlaceholderText.text = %%-locator-get-by-text-text-%%
-### option: Page.getByPlaceholderText.exact = %%-locator-get-by-text-exact-%%
+### param: Page.getByPlaceholder.text = %%-locator-get-by-text-text-%%
+### option: Page.getByPlaceholder.exact = %%-locator-get-by-text-exact-%%
## method: Page.getByRole
diff --git a/docs/src/auth.md b/docs/src/auth.md
index 182503eb1f..c1e279ad71 100644
--- a/docs/src/auth.md
+++ b/docs/src/auth.md
@@ -23,8 +23,8 @@ test.beforeEach(async ({ page }) => {
// Runs before each test and signs in each page.
await page.goto('https://github.com/login');
await page.getByText('Login').click();
- await page.getByLabelText('User Name').fill('username');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('username');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Submit').click();
});
@@ -44,8 +44,8 @@ test.beforeEach(async ({ page }) => {
// Runs before each test and signs in each page.
await page.goto('https://github.com/login');
await page.getByText('Login').click();
- await page.getByLabelText('User name').fill('username');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User name').fill('username');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Submit').click();
});
@@ -64,8 +64,8 @@ await page.goto('https://github.com/login');
// Interact with login form
await page.getByText('Login').click();
-await page.getByLabelText('User Name').fill(USERNAME);
-await page.getByLabelText('Password').fill(PASSWORD);
+await page.getByLabel('User Name').fill(USERNAME);
+await page.getByLabel('Password').fill(PASSWORD);
await page.getByText('Submit').click();
// Continue with the test
```
@@ -75,8 +75,8 @@ Page page = context.newPage();
page.navigate("https://github.com/login");
// Interact with login form
page.getByText("Login").click();
-page.getByLabelText("User Name").fill(USERNAME);
-page.getByLabelText("Password").fill(PASSWORD);
+page.getByLabel("User Name").fill(USERNAME);
+page.getByLabel("Password").fill(PASSWORD);
page.locator("text=Submit").click();
// Continue with the test
```
@@ -87,8 +87,8 @@ await page.goto('https://github.com/login')
# Interact with login form
await page.get_by_text("Login").click()
-await page.get_by_label_text("User Name").fill(USERNAME)
-await page.get_by_label_text("Password").fill(PASSWORD)
+await page.get_by_label("User Name").fill(USERNAME)
+await page.get_by_label("Password").fill(PASSWORD)
await page.get_by_text('Submit').click()
# Continue with the test
```
@@ -99,8 +99,8 @@ page.goto('https://github.com/login')
# Interact with login form
page.get_by_text("Login").click()
-page.get_by_label_text("User Name").fill(USERNAME)
-page.get_by_label_text("Password").fill(PASSWORD)
+page.get_by_label("User Name").fill(USERNAME)
+page.get_by_label("Password").fill(PASSWORD)
page.get_by_text('Submit').click()
# Continue with the test
```
@@ -110,8 +110,8 @@ var page = await context.NewPageAsync();
await page.GotoAsync("https://github.com/login");
// Interact with login form
await page.GetByText("Login").ClickAsync();
-await page.GetByLabelText("User Name").FillAsync(USERNAME);
-await page.GetByLabelText("Password").FillAsync(PASSWORD);
+await page.GetByLabel("User Name").FillAsync(USERNAME);
+await page.GetByLabel("Password").FillAsync(PASSWORD);
await page.GetByText("Submit").ClickAsync();
// Continue with the test
```
@@ -189,8 +189,8 @@ module.exports = async config => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://github.com/login');
- await page.getByLabelText('User Name').fill('user');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('user');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Sign in').click();
// Save signed-in state to 'storageState.json'.
await page.context().storageState({ path: 'storageState.json' });
@@ -206,8 +206,8 @@ async function globalSetup(config: FullConfig) {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://github.com/login');
- await page.getByLabelText('User Name').fill('user');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('user');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Sign in').click();
// Save signed-in state to 'storageState.json'.
await page.context().storageState({ path: 'storageState.json' });
@@ -339,8 +339,8 @@ exports.test = base.extend({
// Make sure we are not using any other storage state.
const page = await browser.newPage({ storageState: undefined });
await page.goto('https://github.com/login');
- await page.getByLabelText('User Name').fill(users[testInfo.workerIndex].username);
- await page.getByLabelText('Password').fill(users[testInfo.workerIndex].password);
+ await page.getByLabel('User Name').fill(users[testInfo.workerIndex].username);
+ await page.getByLabel('Password').fill(users[testInfo.workerIndex].password);
await page.getByText('Sign in').click();
await page.context().storageState({ path: fileName });
await page.close();
@@ -378,8 +378,8 @@ export const test = baseTest.extend({
const page = await browser.newPage({ storageState: undefined });
await page.goto('https://github.com/login');
// Create a unique username for each worker.
- await page.getByLabelText('User Name').fill(users[testInfo.workerIndex].username);
- await page.getByLabelText('Password').fill(users[testInfo.workerIndex].password);
+ await page.getByLabel('User Name').fill(users[testInfo.workerIndex].username);
+ await page.getByLabel('Password').fill(users[testInfo.workerIndex].password);
await page.getByText('Sign in').click();
await page.context().storageState({ path: fileName });
await page.close();
@@ -675,8 +675,8 @@ test.beforeAll(async ({ browser }) => {
// Create page yourself and sign in.
page = await browser.newPage();
await page.goto('https://github.com/login');
- await page.getByLabelText('User Name').fill('user');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('user');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Sign in').click();
});
@@ -706,8 +706,8 @@ test.beforeAll(async ({ browser }) => {
// Create page once and sign in.
page = await browser.newPage();
await page.goto('https://github.com/login');
- await page.getByLabelText('User Name').fill('user');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('user');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Sign in').click();
});
diff --git a/docs/src/frames.md b/docs/src/frames.md
index f06d093978..1a67f24bd8 100644
--- a/docs/src/frames.md
+++ b/docs/src/frames.md
@@ -11,32 +11,32 @@ inside the frame.
```js
// Locate element inside frame
-const username = await page.frameLocator('.frame-class').getByLabelText('User Name');
+const username = await page.frameLocator('.frame-class').getByLabel('User Name');
await username.fill('John');
```
```java
// Locate element inside frame
-Locator username = page.frameLocator(".frame-class").getByLabelText("User Name");
+Locator username = page.frameLocator(".frame-class").getByLabel("User Name");
username.fill("John");
```
```python async
# Locate element inside frame
-username = await page.frame_locator('.frame-class').get_by_label_text('User Name')
+username = await page.frame_locator('.frame-class').get_by_label('User Name')
await username.fill('John')
```
```python sync
# Locate element inside frame
# Get frame using any other selector
-username = page.frame_locator('.frame-class').get_by_label_text('User Name')
+username = page.frame_locator('.frame-class').get_by_label('User Name')
username.fill('John')
```
```csharp
// Locate element inside frame
-var username = await page.FrameLocator(".frame-class").GetByLabelText("User Name");
+var username = await page.FrameLocator(".frame-class").GetByLabel("User Name");
await username.FillAsync("John");
```
diff --git a/docs/src/input.md b/docs/src/input.md
index b1a57e30a7..a2b74023e0 100644
--- a/docs/src/input.md
+++ b/docs/src/input.md
@@ -14,13 +14,13 @@ Using [`method: Locator.fill`] is the easiest way to fill out the form fields. I
await page.getByRole('textbox').fill('Peter');
// Date input
-await page.getByLabelText('Birth date').fill('2020-02-02');
+await page.getByLabel('Birth date').fill('2020-02-02');
// Time input
-await page.getByLabelText('Appointment time').fill('13:15');
+await page.getByLabel('Appointment time').fill('13:15');
// Local datetime input
-await page.getByLabelText('Local time').fill('2020-03-02T05:15');
+await page.getByLabel('Local time').fill('2020-03-02T05:15');
```
```java
@@ -28,13 +28,13 @@ await page.getByLabelText('Local time').fill('2020-03-02T05:15');
page.getByRole("textbox").fill("Peter");
// Date input
-page.getByLabelText("Birth date").fill("2020-02-02");
+page.getByLabel("Birth date").fill("2020-02-02");
// Time input
-page.getByLabelText("Appointment time").fill("13-15");
+page.getByLabel("Appointment time").fill("13-15");
// Local datetime input
-page.getByLabelText("Local time").fill("2020-03-02T05:15");
+page.getByLabel("Local time").fill("2020-03-02T05:15");
```
```python async
@@ -42,13 +42,13 @@ page.getByLabelText("Local time").fill("2020-03-02T05:15");
await page.get_by_role("textbox").fill("Peter")
# Date input
-await page.get_by_label_text("Birth date").fill("2020-02-02")
+await page.get_by_label("Birth date").fill("2020-02-02")
# Time input
-await page.get_by_label_text("Appointment time").fill("13:15")
+await page.get_by_label("Appointment time").fill("13:15")
# Local datetime input
-await page.get_by_label_text("Local time").fill("2020-03-02T05:15")
+await page.get_by_label("Local time").fill("2020-03-02T05:15")
```
```python sync
@@ -56,13 +56,13 @@ await page.get_by_label_text("Local time").fill("2020-03-02T05:15")
page.get_by_role("textbox").fill("Peter")
# Date input
-page.get_by_label_text("Birth date").fill("2020-02-02")
+page.get_by_label("Birth date").fill("2020-02-02")
# Time input
-page.get_by_label_text("Appointment time").fill("13:15")
+page.get_by_label("Appointment time").fill("13:15")
# Local datetime input
-page.get_by_label_text("Local time").fill("2020-03-02T05:15")
+page.get_by_label("Local time").fill("2020-03-02T05:15")
```
```csharp
@@ -70,13 +70,13 @@ page.get_by_label_text("Local time").fill("2020-03-02T05:15")
await page.GetByRole("textbox").FillAsync("Peter");
// Date input
-await page.GetByLabelText("Birth date").FillAsync("2020-02-02");
+await page.GetByLabel("Birth date").FillAsync("2020-02-02");
// Time input
-await page.GetByLabelText("Appointment time").FillAsync("13-15");
+await page.GetByLabel("Appointment time").FillAsync("13-15");
// Local datetime input
-await page.GetByLabelText("Local time").FillAsync("2020-03-02T05:15");
+await page.GetByLabel("Local time").FillAsync("2020-03-02T05:15");
```
## Checkboxes and radio buttons
@@ -85,57 +85,57 @@ Using [`method: Locator.setChecked`] is the easiest way to check and uncheck a c
```js
// Check the checkbox
-await page.getByLabelText('I agree to the terms above').check();
+await page.getByLabel('I agree to the terms above').check();
// Assert the checked state
-expect(await page.getByLabelText('Subscribe to newsletter').isChecked()).toBeTruthy()
+expect(await page.getByLabel('Subscribe to newsletter').isChecked()).toBeTruthy()
// Select the radio button
-await page.getByLabelText('XL').check();
+await page.getByLabel('XL').check();
```
```java
// Check the checkbox
-page.getByLabelText("I agree to the terms above").check();
+page.getByLabel("I agree to the terms above").check();
// Assert the checked state
-assertTrue(page.getByLabelText("Subscribe to newsletter").isChecked());
+assertTrue(page.getByLabel("Subscribe to newsletter").isChecked());
// Select the radio button
-page.getByLabelText("XL").check();
+page.getByLabel("XL").check();
```
```python async
# Check the checkbox
-await page.get_by_label_text('I agree to the terms above').check()
+await page.get_by_label('I agree to the terms above').check()
# Assert the checked state
-assert await page.get_by_label_text('Subscribe to newsletter').is_checked() is True
+assert await page.get_by_label('Subscribe to newsletter').is_checked() is True
# Select the radio button
-await page.get_by_label_text('XL').check()
+await page.get_by_label('XL').check()
```
```python sync
# Check the checkbox
-page.get_by_label_text('I agree to the terms above').check()
+page.get_by_label('I agree to the terms above').check()
# Assert the checked state
-assert page.get_by_label_text('Subscribe to newsletter').is_checked() is True
+assert page.get_by_label('Subscribe to newsletter').is_checked() is True
# Select the radio button
-page.get_by_label_text('XL').check()
+page.get_by_label('XL').check()
```
```csharp
// Check the checkbox
-await page.GetByLabelText("I agree to the terms above").CheckAsync();
+await page.GetByLabel("I agree to the terms above").CheckAsync();
// Assert the checked state
-Assert.True(await page.GetByLabelText("Subscribe to newsletter").IsCheckedAsync());
+Assert.True(await page.GetByLabel("Subscribe to newsletter").IsCheckedAsync());
// Select the radio button
-await page.GetByLabelText("XL").CheckAsync();
+await page.GetByLabel("XL").CheckAsync();
```
## Select options
@@ -145,57 +145,57 @@ You can specify option `value`, or `label` to select. Multiple options can be se
```js
// Single selection matching the value
-await page.getByLabelText('Choose a color').selectOption('blue');
+await page.getByLabel('Choose a color').selectOption('blue');
// Single selection matching the label
-await page.getByLabelText('Choose a color').selectOption({ label: 'Blue' });
+await page.getByLabel('Choose a color').selectOption({ label: 'Blue' });
// Multiple selected items
-await page.getByLabelText('Choose multiple colors').selectOption(['red', 'green', 'blue']);
+await page.getByLabel('Choose multiple colors').selectOption(['red', 'green', 'blue']);
```
```java
// Single selection matching the value
-page.getByLabelText("Choose a color").selectOption("blue");
+page.getByLabel("Choose a color").selectOption("blue");
// Single selection matching the label
-page.getByLabelText("Choose a color").selectOption(new SelectOption().setLabel("Blue"));
+page.getByLabel("Choose a color").selectOption(new SelectOption().setLabel("Blue"));
// Multiple selected items
-page.getByLabelText("Choose multiple colors").selectOption(new String[] {"red", "green", "blue"});
+page.getByLabel("Choose multiple colors").selectOption(new String[] {"red", "green", "blue"});
```
```python async
# Single selection matching the value
-await page.get_by_label_text('Choose a color').select_option('blue')
+await page.get_by_label('Choose a color').select_option('blue')
# Single selection matching the label
-await page.get_by_label_text('Choose a color').select_option(label='Blue')
+await page.get_by_label('Choose a color').select_option(label='Blue')
# Multiple selected items
-await page.get_by_label_text('Choose multiple colors').select_option(['red', 'green', 'blue'])
+await page.get_by_label('Choose multiple colors').select_option(['red', 'green', 'blue'])
```
```python sync
# Single selection matching the value
-page.get_by_label_text('Choose a color').select_option('blue')
+page.get_by_label('Choose a color').select_option('blue')
# Single selection matching the label
-page.get_by_label_text('Choose a color').select_option(label='Blue')
+page.get_by_label('Choose a color').select_option(label='Blue')
# Multiple selected items
-page.get_by_label_text('Choose multiple colors').select_option(['red', 'green', 'blue'])
+page.get_by_label('Choose multiple colors').select_option(['red', 'green', 'blue'])
```
```csharp
// Single selection matching the value
-await page.GetByLabelText("Choose a color").SelectOptionAsync("blue");
+await page.GetByLabel("Choose a color").SelectOptionAsync("blue");
// Single selection matching the label
-await page.GetByLabelText("Choose a color").SelectOptionAsync(new SelectOptionValue { Label = "blue" }));
+await page.GetByLabel("Choose a color").SelectOptionAsync(new SelectOptionValue { Label = "blue" }));
// Multiple selected items
-await page.GetByLabelText("Choose multiple colors").SelectOptionAsync(new[] { "blue", "green", "red" });
+await page.GetByLabel("Choose multiple colors").SelectOptionAsync(new[] { "blue", "green", "red" });
```
## Mouse click
@@ -516,16 +516,16 @@ You can select input files for upload using the [`method: Locator.setInputFiles`
```js
// Select one file
-await page.getByLabelText('Upload file').setInputFiles('myfile.pdf');
+await page.getByLabel('Upload file').setInputFiles('myfile.pdf');
// Select multiple files
-await page.getByLabelText('Upload files').setInputFiles(['file1.txt', 'file2.txt']);
+await page.getByLabel('Upload files').setInputFiles(['file1.txt', 'file2.txt']);
// Remove all the selected files
-await page.getByLabelText('Upload file').setInputFiles([]);
+await page.getByLabel('Upload file').setInputFiles([]);
// Upload buffer from memory
-await page.getByLabelText('Upload file').setInputFiles({
+await page.getByLabel('Upload file').setInputFiles({
name: 'file.txt',
mimeType: 'text/plain',
buffer: Buffer.from('this is test')
@@ -534,31 +534,31 @@ await page.getByLabelText('Upload file').setInputFiles({
```java
// Select one file
-page.getByLabelText("Upload file").setInputFiles(Paths.get("myfile.pdf"));
+page.getByLabel("Upload file").setInputFiles(Paths.get("myfile.pdf"));
// Select multiple files
-page.getByLabelText("Upload files").setInputFiles(new Path[] {Paths.get("file1.txt"), Paths.get("file2.txt")});
+page.getByLabel("Upload files").setInputFiles(new Path[] {Paths.get("file1.txt"), Paths.get("file2.txt")});
// Remove all the selected files
-page.getByLabelText("Upload file").setInputFiles(new Path[0]);
+page.getByLabel("Upload file").setInputFiles(new Path[0]);
// Upload buffer from memory
-page.getByLabelText("Upload file").setInputFiles(new FilePayload(
+page.getByLabel("Upload file").setInputFiles(new FilePayload(
"file.txt", "text/plain", "this is test".getBytes(StandardCharsets.UTF_8)));
```
```python async
# Select one file
-await page.get_by_label_text("Upload file").set_input_files('myfile.pdf')
+await page.get_by_label("Upload file").set_input_files('myfile.pdf')
# Select multiple files
-await page.get_by_label_text("Upload files").set_input_files(['file1.txt', 'file2.txt'])
+await page.get_by_label("Upload files").set_input_files(['file1.txt', 'file2.txt'])
# Remove all the selected files
-await page.get_by_label_text("Upload file").set_input_files([])
+await page.get_by_label("Upload file").set_input_files([])
# Upload buffer from memory
-await page.get_by_label_text("Upload file").set_input_files(
+await page.get_by_label("Upload file").set_input_files(
files=[
{"name": "test.txt", "mimeType": "text/plain", "buffer": b"this is a test"}
],
@@ -567,16 +567,16 @@ await page.get_by_label_text("Upload file").set_input_files(
```python sync
# Select one file
-page.get_by_label_text("Upload file").set_input_files('myfile.pdf')
+page.get_by_label("Upload file").set_input_files('myfile.pdf')
# Select multiple files
-page.get_by_label_text("Upload files").set_input_files(['file1.txt', 'file2.txt'])
+page.get_by_label("Upload files").set_input_files(['file1.txt', 'file2.txt'])
# Remove all the selected files
-page.get_by_label_text("Upload file").set_input_files([])
+page.get_by_label("Upload file").set_input_files([])
# Upload buffer from memory
-page.get_by_label_text("Upload file").set_input_files(
+page.get_by_label("Upload file").set_input_files(
files=[
{"name": "test.txt", "mimeType": "text/plain", "buffer": b"this is a test"}
],
@@ -585,16 +585,16 @@ page.get_by_label_text("Upload file").set_input_files(
```csharp
// Select one file
-await page.GetByLabelText("Upload file").SetInputFilesAsync("myfile.pdf");
+await page.GetByLabel("Upload file").SetInputFilesAsync("myfile.pdf");
// Select multiple files
-await page.GetByLabelText("Upload files").SetInputFilesAsync(new[] { "file1.txt", "file12.txt" });
+await page.GetByLabel("Upload files").SetInputFilesAsync(new[] { "file1.txt", "file12.txt" });
// Remove all the selected files
-await page.GetByLabelText("Upload file").SetInputFilesAsync(new[] {});
+await page.GetByLabel("Upload file").SetInputFilesAsync(new[] {});
// Upload buffer from memory
-await page.GetByLabelText("Upload file").SetInputFilesAsync(new FilePayload
+await page.GetByLabel("Upload file").SetInputFilesAsync(new FilePayload
{
Name = "file.txt",
MimeType = "text/plain",
@@ -650,23 +650,23 @@ await fileChooser.SetFilesAsync("myfile.pdf");
For the dynamic pages that handle focus events, you can focus the given element with [`method: Locator.focus`].
```js
-await page.getByLabelText('Password').focus();
+await page.getByLabel('Password').focus();
```
```java
-page.getByLabelText("Password").focus();
+page.getByLabel("Password").focus();
```
```python async
-await page.get_by_label_text('password').focus()
+await page.get_by_label('password').focus()
```
```python sync
-page.get_by_label_text('password').focus()
+page.get_by_label('password').focus()
```
```csharp
-await page.GetByLabelText("Password").FocusAsync();
+await page.GetByLabel("Password").FocusAsync();
```
## Drag and Drop
diff --git a/docs/src/navigations.md b/docs/src/navigations.md
index 2136568308..80f0e26f2f 100644
--- a/docs/src/navigations.md
+++ b/docs/src/navigations.md
@@ -162,7 +162,7 @@ By default, [`method: Locator.click`] will wait for the navigation step to compl
await page.getByText('Login').click();
// Fill will auto-wait for element on navigated page
-await page.getByLabelText('User Name').fill('John Doe');
+await page.getByLabel('User Name').fill('John Doe');
```
```java
@@ -170,7 +170,7 @@ await page.getByLabelText('User Name').fill('John Doe');
page.getByText("Login").click();
// Fill will auto-wait for element on navigated page
-page.getByLabelText("User Name").fill("John Doe");
+page.getByLabel("User Name").fill("John Doe");
```
```python async
@@ -178,7 +178,7 @@ page.getByLabelText("User Name").fill("John Doe");
await page.get_by_text("Login").click()
# Fill will auto-wait for element on navigated page
-await page.get_by_label_text("User Name").fill("John Doe")
+await page.get_by_label("User Name").fill("John Doe")
```
```python sync
@@ -186,7 +186,7 @@ await page.get_by_label_text("User Name").fill("John Doe")
page.get_by_text("Login").click()
# Fill will auto-wait for element on navigated page
-page.get_by_label_text("User Name").fill("John Doe")
+page.get_by_label("User Name").fill("John Doe")
```
```csharp
@@ -194,7 +194,7 @@ page.get_by_label_text("User Name").fill("John Doe")
await page.GetByText("Login").ClickAsync();
// Fill will auto-wait for element on navigated page
-await page.GetByLabelText("User Name").FillAsync("John Doe");
+await page.GetByLabel("User Name").FillAsync("John Doe");
```
### Custom wait
@@ -235,60 +235,60 @@ Alternatively, page interactions like [`method: Locator.click`] auto-wait for el
// Click will auto-wait for the element and trigger navigation
await page.getByText('Login').click();
// Wait for the element
-await page.getByLabelText('User Name').waitFor();
+await page.getByLabel('User Name').waitFor();
// Click triggers navigation
await page.getByText('Login').click();
// Fill will auto-wait for element
-await page.getByLabelText('User Name').fill('John Doe');
+await page.getByLabel('User Name').fill('John Doe');
```
```java
// Click will auto-wait for the element and trigger navigation
page.getByText("Login").click();
// Wait for the element
-page.getByLabelText("User Name").waitFor();
+page.getByLabel("User Name").waitFor();
// Click triggers navigation
page.getByText("Login").click();
// Fill will auto-wait for element
-page.getByLabelText("User Name").fill("John Doe");
+page.getByLabel("User Name").fill("John Doe");
```
```python async
# Click will auto-wait for the element and trigger navigation
await page.get_by_text("Login").click()
# Wait for the element
-await page.get_by_label_text("User Name").wait_for()
+await page.get_by_label("User Name").wait_for()
# Click triggers navigation
await page.get_by_text("Login").click()
# Fill will auto-wait for element
-await page.get_by_label_text("User Name").fill("John Doe")
+await page.get_by_label("User Name").fill("John Doe")
```
```python sync
# Click triggers navigation
page.get_by_text("Login").click()
# Click will auto-wait for the element
-page.get_by_label_text("User Name").wait_for()
+page.get_by_label("User Name").wait_for()
# Click triggers navigation
page.get_by_text("Login").click()
# Fill will auto-wait for element
-page.get_by_label_text("User Name").fill("John Doe")
+page.get_by_label("User Name").fill("John Doe")
```
```csharp
// Click will auto-wait for the element and trigger navigation
await page.GetByText("Login").ClickAsync();
// Wait for the element
-await page.GetByLabelText("User Name").WaitForAsync();
+await page.GetByLabel("User Name").WaitForAsync();
// Click triggers navigation
await page.GetByText("Login").ClickAsync();
// Fill will auto-wait for element
-await page.GetByLabelText("User Name").FillAsync("John Doe");
+await page.GetByLabel("User Name").FillAsync("John Doe");
```
### Asynchronous navigation
diff --git a/docs/src/test-advanced-js.md b/docs/src/test-advanced-js.md
index bcb3d181a0..4d12c953a0 100644
--- a/docs/src/test-advanced-js.md
+++ b/docs/src/test-advanced-js.md
@@ -224,8 +224,8 @@ module.exports = async config => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto(baseURL);
- await page.getByLabelText('User Name').fill('user');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('user');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Sign in').click();
await page.context().storageState({ path: storageState });
await browser.close();
@@ -241,8 +241,8 @@ async function globalSetup(config: FullConfig) {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto(baseURL!);
- await page.getByLabelText('User Name').fill('user');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('user');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Sign in').click();
await page.context().storageState({ path: storageState as string });
await browser.close();
@@ -373,8 +373,8 @@ module.exports = async config => {
try {
await context.tracing.start({ screenshots: true, snapshots: true });
await page.goto(baseURL);
- await page.getByLabelText('User Name').fill('user');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('user');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Sign in').click();
await context.storageState({ path: storageState });
await context.tracing.stop({
@@ -403,8 +403,8 @@ async function globalSetup(config: FullConfig) {
try {
await context.tracing.start({ screenshots: true, snapshots: true });
await page.goto(baseURL!);
- await page.getByLabelText('User Name').fill('user');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('user');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Sign in').click();
await context.storageState({ path: storageState as string });
await context.tracing.stop({
diff --git a/docs/src/test-api/class-fixtures.md b/docs/src/test-api/class-fixtures.md
index f0f60cd15d..b68c101b4e 100644
--- a/docs/src/test-api/class-fixtures.md
+++ b/docs/src/test-api/class-fixtures.md
@@ -77,8 +77,8 @@ const { test, expect } = require('@playwright/test');
test('basic test', async ({ page }) => {
await page.goto('/signin');
- await page.getByLabelText('User Name').fill('user');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('user');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Sign in').click();
// ...
});
@@ -89,8 +89,8 @@ import { test, expect } from '@playwright/test';
test('basic test', async ({ page }) => {
await page.goto('/signin');
- await page.getByLabelText('User Name').fill('user');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('user');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Sign in').click();
// ...
});
diff --git a/docs/src/test-auth-js.md b/docs/src/test-auth-js.md
index 17257eaeac..7f48d6ed11 100644
--- a/docs/src/test-auth-js.md
+++ b/docs/src/test-auth-js.md
@@ -24,8 +24,8 @@ test.beforeEach(async ({ page }) => {
// Runs before each test and signs in each page.
await page.goto('https://github.com/login');
await page.getByText('Login').click();
- await page.getByLabelText('User Name').fill('user');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('user');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Submit').click();
});
@@ -45,8 +45,8 @@ test.beforeEach(async ({ page }) => {
// Runs before each test and signs in each page.
await page.goto('https://github.com/login');
await page.getByText('Login').click();
- await page.getByLabelText('User Name').fill('user');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('user');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Sign in').click();
});
@@ -77,8 +77,8 @@ module.exports = async config => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://github.com/login');
- await page.getByLabelText('User Name').fill('user');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('user');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Sign in').click();
// Save signed-in state to 'storageState.json'.
await page.context().storageState({ path: 'storageState.json' });
@@ -94,8 +94,8 @@ async function globalSetup(config: FullConfig) {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://github.com/login');
- await page.getByLabelText('User Name').fill('user');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('user');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Sign in').click();
// Save signed-in state to 'storageState.json'.
await page.context().storageState({ path: 'storageState.json' });
@@ -226,8 +226,8 @@ exports.test = base.extend({
// Make sure we are not using any other storage state.
const page = await browser.newPage({ storageState: undefined });
await page.goto('https://github.com/login');
- await page.getByLabelText('User Name').fill(users[testInfo.workerIndex].username);
- await page.getByLabelText('Password').fill(users[testInfo.workerIndex].password);
+ await page.getByLabel('User Name').fill(users[testInfo.workerIndex].username);
+ await page.getByLabel('Password').fill(users[testInfo.workerIndex].password);
await page.getByText('Sign in').click();
await page.context().storageState({ path: fileName });
await page.close();
@@ -265,8 +265,8 @@ export const test = baseTest.extend({
const page = await browser.newPage({ storageState: undefined });
await page.goto('https://github.com/login');
// Create a unique username for each worker.
- await page.getByLabelText('User Name').fill(users[testInfo.workerIndex].username);
- await page.getByLabelText('Password').fill(users[testInfo.workerIndex].password);
+ await page.getByLabel('User Name').fill(users[testInfo.workerIndex].username);
+ await page.getByLabel('Password').fill(users[testInfo.workerIndex].password);
await page.getByText('Sign in').click();
await page.context().storageState({ path: fileName });
await page.close();
@@ -558,8 +558,8 @@ test.beforeAll(async ({ browser }) => {
// Create page yourself and sign in.
page = await browser.newPage();
await page.goto('https://github.com/login');
- await page.getByLabelText('User Name').fill('user');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('user');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Sign in').click();
});
@@ -589,8 +589,8 @@ test.beforeAll(async ({ browser }) => {
// Create page once and sign in.
page = await browser.newPage();
await page.goto('https://github.com/login');
- await page.getByLabelText('User Name').fill('user');
- await page.getByLabelText('Password').fill('password');
+ await page.getByLabel('User Name').fill('user');
+ await page.getByLabel('Password').fill('password');
await page.getByText('Sign in').click();
});
diff --git a/docs/src/test-fixtures-js.md b/docs/src/test-fixtures-js.md
index f3d6923be5..d4ddecafb5 100644
--- a/docs/src/test-fixtures-js.md
+++ b/docs/src/test-fixtures-js.md
@@ -334,8 +334,8 @@ exports.test = base.test.extend({
// Create the account with Playwright.
const page = await browser.newPage();
await page.goto('/signup');
- await page.getByLabelText('User Name').fill(username);
- await page.getByLabelText('Password').fill(password);
+ await page.getByLabel('User Name').fill(username);
+ await page.getByLabel('Password').fill(password);
await page.getByText('Sign up').click();
// Make sure everything is ok.
await expect(page.locator('#result')).toHaveText('Success');
@@ -350,8 +350,8 @@ exports.test = base.test.extend({
// Sign in with our account.
const { username, password } = account;
await page.goto('/signin');
- await page.getByLabelText('User Name').fill(username);
- await page.getByLabelText('Password').fill(password);
+ await page.getByLabel('User Name').fill(username);
+ await page.getByLabel('Password').fill(password);
await page.getByText('Sign in').click();
await expect(page.locator('#userinfo')).toHaveText(username);
@@ -381,8 +381,8 @@ export const test = base.extend<{}, { account: Account }>({
// Create the account with Playwright.
const page = await browser.newPage();
await page.goto('/signup');
- await page.getByLabelText('User Name').fill(username);
- await page.getByLabelText('Password').fill(password);
+ await page.getByLabel('User Name').fill(username);
+ await page.getByLabel('Password').fill(password);
await page.getByText('Sign up').click();
// Make sure everything is ok.
await expect(page.locator('#result')).toHaveText('Success');
@@ -397,8 +397,8 @@ export const test = base.extend<{}, { account: Account }>({
// Sign in with our account.
const { username, password } = account;
await page.goto('/signin');
- await page.getByLabelText('User Name').fill(username);
- await page.getByLabelText('Password').fill(password);
+ await page.getByLabel('User Name').fill(username);
+ await page.getByLabel('Password').fill(password);
await page.getByText('Sign in').click();
await expect(page.locator('#userinfo')).toHaveText(username);
diff --git a/docs/src/test-parameterize-js.md b/docs/src/test-parameterize-js.md
index f6723383c7..8d3412f1e1 100644
--- a/docs/src/test-parameterize-js.md
+++ b/docs/src/test-parameterize-js.md
@@ -143,7 +143,7 @@ exports.test = base.test.extend({
page: async ({ page, person }, use) => {
await page.goto('/chat');
// We use "person" parameter as a "name" for the chat room.
- await page.getByLabelText('User Name').fill(person);
+ await page.getByLabel('User Name').fill(person);
await page.getByText('Enter chat room').click();
// Each test will get a "page" that already has the person name.
await use(page);
@@ -168,7 +168,7 @@ export const test = base.test.extend<TestOptions>({
page: async ({ page, person }, use) => {
await page.goto('/chat');
// We use "person" parameter as a "name" for the chat room.
- await page.getByLabelText('User Name').fill(person);
+ await page.getByLabel('User Name').fill(person);
await page.getByText('Enter chat room').click();
// Each test will get a "page" that already has the person name.
await use(page);
@@ -190,8 +190,8 @@ For example, consider the following test file that needs a username and a passwo
// example.spec.js
test(`example test`, async ({ page }) => {
// ...
- await page.getByLabelText('User Name').fill(process.env.USERNAME);
- await page.getByLabelText('Password').fill(process.env.PASSWORD);
+ await page.getByLabel('User Name').fill(process.env.USERNAME);
+ await page.getByLabel('Password').fill(process.env.PASSWORD);
});
```
@@ -199,8 +199,8 @@ test(`example test`, async ({ page }) => {
// example.spec.ts
test(`example test`, async ({ page }) => {
// ...
- await page.getByLabelText('User Name').fill(process.env.USERNAME);
- await page.getByLabelText('Password').fill(process.env.PASSWORD);
+ await page.getByLabel('User Name').fill(process.env.USERNAME);
+ await page.getByLabel('Password').fill(process.env.PASSWORD);
});
```
diff --git a/docs/src/test-typescript-js.md b/docs/src/test-typescript-js.md
index 6fcc22468f..83b0d7449d 100644
--- a/docs/src/test-typescript-js.md
+++ b/docs/src/test-typescript-js.md
@@ -25,8 +25,8 @@ import { test, expect } from '@playwright/test';
import { username, password } from './helper';
test('example', async ({ page }) => {
- await page.getByLabelText('User Name').fill(username);
- await page.getByLabelText('Password').fill(password);
+ await page.getByLabel('User Name').fill(username);
+ await page.getByLabel('Password').fill(password);
});
```
@@ -62,8 +62,8 @@ import { test, expect } from '@playwright/test';
import { username, password } from './helper.ts';
test('example', async ({ page }) => {
- await page.getByLabelText('User Name').fill(username);
- await page.getByLabelText('Password').fill(password);
+ await page.getByLabel('User Name').fill(username);
+ await page.getByLabel('Password').fill(password);
});
```
@@ -96,8 +96,8 @@ import { test, expect } from '@playwright/test';
import { username, password } from '@myhelper/credentials';
test('example', async ({ page }) => {
- await page.getByLabelText('User Name').fill(username);
- await page.getByLabelText('Password').fill(password);
+ await page.getByLabel('User Name').fill(username);
+ await page.getByLabel('Password').fill(password);
});
```
diff --git a/docs/src/testing-library-js.md b/docs/src/testing-library-js.md
index 9832245762..814e565167 100644
--- a/docs/src/testing-library-js.md
+++ b/docs/src/testing-library-js.md
@@ -23,11 +23,11 @@ If you use DOM Testing Library in the browser (for example, you bundle end-to-en
| [user events](https://testing-library.com/docs/user-event/intro) | [actions](./api/class-locator) |
| `await user.click(screen.getByText('Click me'))` | `await component.getByText('Click me').click()` |
| `await user.click(await screen.findByText('Click me'))` | `await component.getByText('Click me').click()` |
-| `await user.type(screen.getByLabelText('Password'), 'secret')` | `await component.getByLabelText('Password').fill('secret')` |
-| `expect(screen.getByLabelText('Password')).toHaveValue('secret')` | `await expect(component.getByLabelText('Password')).toHaveValue('secret')` |
+| `await user.type(screen.getByLabel('Password'), 'secret')` | `await component.getByLabel('Password').fill('secret')` |
+| `expect(screen.getByLabel('Password')).toHaveValue('secret')` | `await expect(component.getByLabel('Password')).toHaveValue('secret')` |
| `screen.findByText('...')` | `component.getByText('...')` |
| `screen.getByTestId('...')` | `component.getByTestId('...')` |
-| `screen.queryByPlaceholderText('...')` | `component.getByPlaceholderText('...')` |
+| `screen.queryByPlaceholderText('...')` | `component.getByPlaceholder('...')` |
| `screen.getByRole('button', { pressed: true })` | `component.getByRole('button', { pressed: true })`|
## Example
@@ -45,8 +45,8 @@ test('should sign in', async () => {
render(<SignInPage />);
// Perform actions.
- await user.type(screen.getByLabelText('Username'), 'John');
- await user.type(screen.getByLabelText('Password'), 'secret');
+ await user.type(screen.getByLabel('Username'), 'John');
+ await user.type(screen.getByLabel('Password'), 'secret');
await user.click(screen.getByText('Sign in'));
// Verify signed in state by waiting until "Welcome" message appears.
diff --git a/packages/playwright-core/src/client/frame.ts b/packages/playwright-core/src/client/frame.ts
index 9a40225f12..6dbc971a37 100644
--- a/packages/playwright-core/src/client/frame.ts
+++ b/packages/playwright-core/src/client/frame.ts
@@ -307,12 +307,12 @@ export class Frame extends ChannelOwner<channels.FrameChannel> implements api.Fr
return this.locator(Locator.getByAltTextSelector(text, options));
}
- getByLabelText(text: string | RegExp, options?: { exact?: boolean }): Locator {
- return this.locator(Locator.getByLabelTextSelector(text, options));
+ getByLabel(text: string | RegExp, options?: { exact?: boolean }): Locator {
+ return this.locator(Locator.getByLabelSelector(text, options));
}
- getByPlaceholderText(text: string | RegExp, options?: { exact?: boolean }): Locator {
- return this.locator(Locator.getByPlaceholderTextSelector(text, options));
+ getByPlaceholder(text: string | RegExp, options?: { exact?: boolean }): Locator {
+ return this.locator(Locator.getByPlaceholderSelector(text, options));
}
getByText(text: string | RegExp, options?: { exact?: boolean }): Locator {
diff --git a/packages/playwright-core/src/client/locator.ts b/packages/playwright-core/src/client/locator.ts
index 6d4386b93b..553ab3561e 100644
--- a/packages/playwright-core/src/client/locator.ts
+++ b/packages/playwright-core/src/client/locator.ts
@@ -61,7 +61,7 @@ export class Locator implements api.Locator {
return `attr=[${attrName}=${JSON.stringify(text)}${options?.exact ? 's' : 'i'}]`;
}
- static getByLabelTextSelector(text: string | RegExp, options?: { exact?: boolean }): string {
+ static getByLabelSelector(text: string | RegExp, options?: { exact?: boolean }): string {
if (!isString(text))
return `text=${text}`;
const escaped = JSON.stringify(text);
@@ -77,7 +77,7 @@ export class Locator implements api.Locator {
return Locator.getByAttributeTextSelector('title', text, options);
}
- static getByPlaceholderTextSelector(text: string | RegExp, options?: { exact?: boolean }): string {
+ static getByPlaceholderSelector(text: string | RegExp, options?: { exact?: boolean }): string {
return Locator.getByAttributeTextSelector('placeholder', text, options);
}
@@ -215,12 +215,12 @@ export class Locator implements api.Locator {
return this.locator(Locator.getByAltTextSelector(text, options));
}
- getByLabelText(text: string | RegExp, options?: { exact?: boolean }): Locator {
- return this.locator(Locator.getByLabelTextSelector(text, options));
+ getByLabel(text: string | RegExp, options?: { exact?: boolean }): Locator {
+ return this.locator(Locator.getByLabelSelector(text, options));
}
- getByPlaceholderText(text: string | RegExp, options?: { exact?: boolean }): Locator {
- return this.locator(Locator.getByPlaceholderTextSelector(text, options));
+ getByPlaceholder(text: string | RegExp, options?: { exact?: boolean }): Locator {
+ return this.locator(Locator.getByPlaceholderSelector(text, options));
}
getByText(text: string | RegExp, options?: { exact?: boolean }): Locator {
@@ -417,12 +417,12 @@ export class FrameLocator implements api.FrameLocator {
return this.locator(Locator.getByAltTextSelector(text, options));
}
- getByLabelText(text: string | RegExp, options?: { exact?: boolean }): Locator {
- return this.locator(Locator.getByLabelTextSelector(text, options));
+ getByLabel(text: string | RegExp, options?: { exact?: boolean }): Locator {
+ return this.locator(Locator.getByLabelSelector(text, options));
}
- getByPlaceholderText(text: string | RegExp, options?: { exact?: boolean }): Locator {
- return this.locator(Locator.getByPlaceholderTextSelector(text, options));
+ getByPlaceholder(text: string | RegExp, options?: { exact?: boolean }): Locator {
+ return this.locator(Locator.getByPlaceholderSelector(text, options));
}
getByText(text: string | RegExp, options?: { exact?: boolean }): Locator {
diff --git a/packages/playwright-core/src/client/page.ts b/packages/playwright-core/src/client/page.ts
index 42cfac43b1..4b9b7bc28f 100644
--- a/packages/playwright-core/src/client/page.ts
+++ b/packages/playwright-core/src/client/page.ts
@@ -572,12 +572,12 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Page
return this.mainFrame().getByAltText(text, options);
}
- getByLabelText(text: string | RegExp, options?: { exact?: boolean }): Locator {
- return this.mainFrame().getByLabelText(text, options);
+ getByLabel(text: string | RegExp, options?: { exact?: boolean }): Locator {
+ return this.mainFrame().getByLabel(text, options);
}
- getByPlaceholderText(text: string | RegExp, options?: { exact?: boolean }): Locator {
- return this.mainFrame().getByPlaceholderText(text, options);
+ getByPlaceholder(text: string | RegExp, options?: { exact?: boolean }): Locator {
+ return this.mainFrame().getByPlaceholder(text, options);
}
getByText(text: string | RegExp, options?: { exact?: boolean }): Locator {
diff --git a/packages/playwright-core/src/server/recorder/csharp.ts b/packages/playwright-core/src/server/recorder/csharp.ts
index 8966c9fc97..932bd3afe3 100644
--- a/packages/playwright-core/src/server/recorder/csharp.ts
+++ b/packages/playwright-core/src/server/recorder/csharp.ts
@@ -247,9 +247,9 @@ export class CSharpLanguageGenerator implements LanguageGenerator {
case 'alt':
return toCallWithExact('GetByAltText', body, !!options.exact);
case 'placeholder':
- return toCallWithExact('GetByPlaceholderText', body, !!options.exact);
+ return toCallWithExact('GetByPlaceholder', body, !!options.exact);
case 'label':
- return toCallWithExact('GetByLabelText', body, !!options.exact);
+ return toCallWithExact('GetByLabel', body, !!options.exact);
case 'title':
return toCallWithExact('GetByTitle', body, !!options.exact);
default:
diff --git a/packages/playwright-core/src/server/recorder/java.ts b/packages/playwright-core/src/server/recorder/java.ts
index 2395fee007..e1a237b47a 100644
--- a/packages/playwright-core/src/server/recorder/java.ts
+++ b/packages/playwright-core/src/server/recorder/java.ts
@@ -191,9 +191,9 @@ export class JavaLanguageGenerator implements LanguageGenerator {
case 'alt':
return toCallWithExact(clazz, 'getByAltText', body, !!options.exact);
case 'placeholder':
- return toCallWithExact(clazz, 'getByPlaceholderText', body, !!options.exact);
+ return toCallWithExact(clazz, 'getByPlaceholder', body, !!options.exact);
case 'label':
- return toCallWithExact(clazz, 'getByLabelText', body, !!options.exact);
+ return toCallWithExact(clazz, 'getByLabel', body, !!options.exact);
case 'title':
return toCallWithExact(clazz, 'getByTitle', body, !!options.exact);
default:
diff --git a/packages/playwright-core/src/server/recorder/javascript.ts b/packages/playwright-core/src/server/recorder/javascript.ts
index 6e46936927..2be5b190ab 100644
--- a/packages/playwright-core/src/server/recorder/javascript.ts
+++ b/packages/playwright-core/src/server/recorder/javascript.ts
@@ -228,9 +228,9 @@ ${useText ? '\ntest.use(' + useText + ');\n' : ''}
case 'alt':
return toCallWithExact('getByAltText', body, !!options.exact);
case 'placeholder':
- return toCallWithExact('getByPlaceholderText', body, !!options.exact);
+ return toCallWithExact('getByPlaceholder', body, !!options.exact);
case 'label':
- return toCallWithExact('getByLabelText', body, !!options.exact);
+ return toCallWithExact('getByLabel', body, !!options.exact);
case 'title':
return toCallWithExact('getByTitle', body, !!options.exact);
default:
diff --git a/packages/playwright-core/src/server/recorder/python.ts b/packages/playwright-core/src/server/recorder/python.ts
index 3f49bc61ec..631ce3a56d 100644
--- a/packages/playwright-core/src/server/recorder/python.ts
+++ b/packages/playwright-core/src/server/recorder/python.ts
@@ -246,9 +246,9 @@ with sync_playwright() as playwright:
case 'alt':
return toCallWithExact('get_by_alt_text', body, !!options.exact);
case 'placeholder':
- return toCallWithExact('get_by_placeholder_text', body, !!options.exact);
+ return toCallWithExact('get_by_placeholder', body, !!options.exact);
case 'label':
- return toCallWithExact('get_by_label_text', body, !!options.exact);
+ return toCallWithExact('get_by_label', body, !!options.exact);
case 'title':
return toCallWithExact('get_by_title', body, !!options.exact);
default:
diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts
index c07f5928d2..3a24c1d91c 100644
--- a/packages/playwright-core/types/types.d.ts
+++ b/packages/playwright-core/types/types.d.ts
@@ -2485,7 +2485,7 @@ export interface Page {
* @param text Text to locate the element for.
* @param options
*/
- getByLabelText(text: string|RegExp, options?: {
+ getByLabel(text: string|RegExp, options?: {
/**
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
*/
@@ -2503,7 +2503,7 @@ export interface Page {
* @param text Text to locate the element for.
* @param options
*/
- getByPlaceholderText(text: string|RegExp, options?: {
+ getByPlaceholder(text: string|RegExp, options?: {
/**
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
*/
@@ -5571,7 +5571,7 @@ export interface Frame {
* @param text Text to locate the element for.
* @param options
*/
- getByLabelText(text: string|RegExp, options?: {
+ getByLabel(text: string|RegExp, options?: {
/**
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
*/
@@ -5589,7 +5589,7 @@ export interface Frame {
* @param text Text to locate the element for.
* @param options
*/
- getByPlaceholderText(text: string|RegExp, options?: {
+ getByPlaceholder(text: string|RegExp, options?: {
/**
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
*/
@@ -10005,7 +10005,7 @@ export interface Locator {
* @param text Text to locate the element for.
* @param options
*/
- getByLabelText(text: string|RegExp, options?: {
+ getByLabel(text: string|RegExp, options?: {
/**
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
*/
@@ -10023,7 +10023,7 @@ export interface Locator {
* @param text Text to locate the element for.
* @param options
*/
- getByPlaceholderText(text: string|RegExp, options?: {
+ getByPlaceholder(text: string|RegExp, options?: {
/**
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
*/
@@ -10746,7 +10746,7 @@ export interface Locator {
* An example of typing into a text field and then submitting the form:
*
* ```js
- * const element = page.getByLabelText('Password');
+ * const element = page.getByLabel('Password');
* await element.type('my password');
* await element.press('Enter');
* ```
@@ -15260,7 +15260,7 @@ export interface FrameLocator {
* @param text Text to locate the element for.
* @param options
*/
- getByLabelText(text: string|RegExp, options?: {
+ getByLabel(text: string|RegExp, options?: {
/**
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
*/
@@ -15278,7 +15278,7 @@ export interface FrameLocator {
* @param text Text to locate the element for.
* @param options
*/
- getByPlaceholderText(text: string|RegExp, options?: {
+ getByPlaceholder(text: string|RegExp, options?: {
/**
* Whether to find an exact match: case-sensitive and whole-string. Default to false.
*/
diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.ts
index 289bf03f1a..84853d1c92 100644
--- a/packages/playwright-test/types/test.d.ts
+++ b/packages/playwright-test/types/test.d.ts
@@ -3078,8 +3078,8 @@ export interface PlaywrightTestArgs {
*
* test('basic test', async ({ page }) => {
* await page.goto('/signin');
- * await page.getByLabelText('User Name').fill('user');
- * await page.getByLabelText('Password').fill('password');
+ * await page.getByLabel('User Name').fill('user');
+ * await page.getByLabel('Password').fill('password');
* await page.getByText('Sign in').click();
* // ...
* });
@@ -3277,7 +3277,7 @@ interface LocatorAssertions {
* Ensures the [Locator] points to a checked input.
*
* ```js
- * const locator = page.getByLabelText('Subscribe to newsletter');
+ * const locator = page.getByLabel('Subscribe to newsletter');
* await expect(locator).toBeChecked();
* ```
*
diff --git a/tests/library/inspector/cli-codegen-3.spec.ts b/tests/library/inspector/cli-codegen-3.spec.ts
index 2ec12994a4..298646f4a9 100644
--- a/tests/library/inspector/cli-codegen-3.spec.ts
+++ b/tests/library/inspector/cli-codegen-3.spec.ts
@@ -261,7 +261,7 @@ test.describe('cli codegen', () => {
expect(message.text()).toBe('click');
});
- test('should generate getByPlaceholderText', async ({ page, openRecorder }) => {
+ test('should generate getByPlaceholder', async ({ page, openRecorder }) => {
const recorder = await openRecorder();
await recorder.setContentAndWait(`<input placeholder="Country"></input>`);
@@ -275,19 +275,19 @@ test.describe('cli codegen', () => {
]);
expect.soft(sources.get('JavaScript').text).toContain(`
- await page.getByPlaceholderText('Country').click();`);
+ await page.getByPlaceholder('Country').click();`);
expect.soft(sources.get('Python').text).toContain(`
- page.get_by_placeholder_text("Country").click()`);
+ page.get_by_placeholder("Country").click()`);
expect.soft(sources.get('Python Async').text).toContain(`
- await page.get_by_placeholder_text("Country").click()`);
+ await page.get_by_placeholder("Country").click()`);
expect.soft(sources.get('Java').text).toContain(`
- page.getByPlaceholderText("Country").click()`);
+ page.getByPlaceholder("Country").click()`);
expect.soft(sources.get('C#').text).toContain(`
- await page.GetByPlaceholderText("Country").ClickAsync();`);
+ await page.GetByPlaceholder("Country").ClickAsync();`);
});
test('should generate getByAltText', async ({ page, openRecorder }) => {
diff --git a/tests/page/locator-frame.spec.ts b/tests/page/locator-frame.spec.ts
index 4755141021..f2f94d766e 100644
--- a/tests/page/locator-frame.spec.ts
+++ b/tests/page/locator-frame.spec.ts
@@ -248,9 +248,9 @@ it('getBy coverage', async ({ page, server }) => {
await expect(button1).toHaveText('Hello iframe');
await expect(button2).toHaveText('Hello iframe');
await expect(button3).toHaveText('Hello iframe');
- const input1 = page.frameLocator('iframe').getByLabelText('Name');
+ const input1 = page.frameLocator('iframe').getByLabel('Name');
await expect(input1).toHaveValue('');
- const input2 = page.frameLocator('iframe').getByPlaceholderText('Placeholder');
+ const input2 = page.frameLocator('iframe').getByPlaceholder('Placeholder');
await expect(input2).toHaveValue('');
const input3 = page.frameLocator('iframe').getByAltText('Alternative');
await expect(input3).toHaveValue('');
diff --git a/tests/page/selectors-get-by.spec.ts b/tests/page/selectors-get-by.spec.ts
index 7c04ee4b20..547ee3e5d3 100644
--- a/tests/page/selectors-get-by.spec.ts
+++ b/tests/page/selectors-get-by.spec.ts
@@ -37,26 +37,26 @@ it('getByText should work', async ({ page }) => {
expect(await page.getByText('ye', { exact: true }).first().evaluate(e => e.outerHTML)).toContain('> ye </div>');
});
-it('getByLabelText should work', async ({ page }) => {
+it('getByLabel should work', async ({ page }) => {
await page.setContent(`<div><label for=target>Name</label><input id=target type=text></div>`);
expect(await page.getByText('Name').evaluate(e => e.nodeName)).toBe('LABEL');
- expect(await page.getByLabelText('Name').evaluate(e => e.nodeName)).toBe('INPUT');
- expect(await page.mainFrame().getByLabelText('Name').evaluate(e => e.nodeName)).toBe('INPUT');
- expect(await page.locator('div').getByLabelText('Name').evaluate(e => e.nodeName)).toBe('INPUT');
+ expect(await page.getByLabel('Name').evaluate(e => e.nodeName)).toBe('INPUT');
+ expect(await page.mainFrame().getByLabel('Name').evaluate(e => e.nodeName)).toBe('INPUT');
+ expect(await page.locator('div').getByLabel('Name').evaluate(e => e.nodeName)).toBe('INPUT');
});
-it('getByPlaceholderText should work', async ({ page }) => {
+it('getByPlaceholder should work', async ({ page }) => {
await page.setContent(`<div>
<input placeholder='Hello'>
<input placeholder='Hello World'>
</div>`);
- await expect(page.getByPlaceholderText('hello')).toHaveCount(2);
- await expect(page.getByPlaceholderText('Hello', { exact: true })).toHaveCount(1);
- await expect(page.getByPlaceholderText(/wor/i)).toHaveCount(1);
+ await expect(page.getByPlaceholder('hello')).toHaveCount(2);
+ await expect(page.getByPlaceholder('Hello', { exact: true })).toHaveCount(1);
+ await expect(page.getByPlaceholder(/wor/i)).toHaveCount(1);
// Coverage
- await expect(page.mainFrame().getByPlaceholderText('hello')).toHaveCount(2);
- await expect(page.locator('div').getByPlaceholderText('hello')).toHaveCount(2);
+ await expect(page.mainFrame().getByPlaceholder('hello')).toHaveCount(2);
+ await expect(page.locator('div').getByPlaceholder('hello')).toHaveCount(2);
});
it('getByAltText should work', async ({ page }) => {