2021-10-22 16:56:58 -07:00
# class: LocatorAssertions
2022-07-05 16:24:50 -08:00
* since: v1.17
2021-10-22 16:56:58 -07:00
2021-11-24 21:58:35 +01:00
The [LocatorAssertions] class provides assertion methods that can be used to make assertions about the [Locator] state in the tests. A new instance of [LocatorAssertions] is created by calling [`method: PlaywrightAssertions.expectLocator` ]:
2021-11-09 12:44:02 -08:00
2021-11-30 20:04:44 +01:00
```js
import { test, expect } from '@playwright/test ';
test('status becomes submitted', async ({ page }) => {
// ...
2022-07-13 11:50:18 +02:00
await page.locator('#submit -button').click();
2021-11-30 20:04:44 +01:00
await expect(page.locator('.status')).toHaveText('Submitted');
});
```
2021-11-09 12:44:02 -08:00
```java
...
import static com.microsoft.playwright.assertions.PlaywrightAssertions.assertThat;
public class TestLocator {
...
@Test
void statusBecomesSubmitted() {
...
2022-07-13 11:50:18 +02:00
page.locator("#submit -button").click();
2021-11-09 12:44:02 -08:00
assertThat(page.locator(".status")).hasText("Submitted");
}
}
```
2021-10-22 16:56:58 -07:00
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import Page, expect
async def test_status_becomes_submitted(page: Page) -> None:
# ..
2022-07-13 11:50:18 +02:00
await page.locator("#submit -button").click()
2021-11-30 20:04:44 +01:00
await expect(page.locator(".status")).to_have_text("Submitted")
```
```python sync
from playwright.sync_api import Page, expect
def test_status_becomes_submitted(page: Page) -> None:
# ..
2022-07-13 11:50:18 +02:00
page.locator("#submit -button").click()
2021-11-30 20:04:44 +01:00
expect(page.locator(".status")).to_have_text("Submitted")
```
2022-02-21 14:01:53 +01:00
```csharp
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Playwright.NUnit;
using NUnit.Framework;
2022-04-19 21:23:26 +03:00
namespace PlaywrightTests;
public class ExampleTests : PageTest
2022-02-21 14:01:53 +01:00
{
2022-04-19 21:23:26 +03:00
[Test]
public async Task StatusBecomesSubmitted()
2022-02-21 14:01:53 +01:00
{
2022-04-19 21:23:26 +03:00
// ..
2022-07-13 11:50:18 +02:00
await Page.Locator("#submit -button").ClickAsync();
2022-04-19 21:23:26 +03:00
await Expect(Page.Locator(".status")).ToHaveTextAsync("Submitted");
2022-02-21 14:01:53 +01:00
}
}
```
2022-03-02 15:03:33 -08:00
## property: LocatorAssertions.not
2022-07-05 16:24:50 -08:00
* since: v1.20
2022-02-21 14:01:53 +01:00
* langs: java, js, csharp
2021-11-18 00:46:30 +01:00
- returns: < [LocatorAssertions]>
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
Makes the assertion check for the opposite condition. For example, this code tests that the Locator doesn't contain text `"error"` :
2021-10-22 16:56:58 -07:00
2021-11-30 20:04:44 +01:00
```js
await expect(locator).not.toContainText('error');
```
2021-10-22 16:56:58 -07:00
```java
2021-11-18 00:46:30 +01:00
assertThat(locator).not().containsText("error");
2021-10-22 16:56:58 -07:00
```
2022-02-21 14:01:53 +01:00
```csharp
await Expect(locator).Not.ToContainTextAsync("error");
```
## async method: LocatorAssertions.NotToBeChecked
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs: python
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
The opposite of [`method: LocatorAssertions.toBeChecked` ].
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToBeChecked.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToBeChecked.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.NotToBeDisabled
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs: python
The opposite of [`method: LocatorAssertions.toBeDisabled` ].
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToBeDisabled.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToBeDisabled.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.NotToBeEditable
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs: python
The opposite of [`method: LocatorAssertions.toBeEditable` ].
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToBeEditable.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToBeEditable.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.NotToBeEmpty
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs: python
The opposite of [`method: LocatorAssertions.toBeEmpty` ].
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToBeEmpty.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToBeEmpty.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.NotToBeEnabled
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs: python
The opposite of [`method: LocatorAssertions.toBeEnabled` ].
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToBeEnabled.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToBeEnabled.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.NotToBeFocused
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs: python
The opposite of [`method: LocatorAssertions.toBeFocused` ].
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToBeFocused.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToBeFocused.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.NotToBeHidden
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs: python
The opposite of [`method: LocatorAssertions.toBeHidden` ].
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToBeHidden.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToBeHidden.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.NotToBeVisible
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs: python
The opposite of [`method: LocatorAssertions.toBeVisible` ].
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToBeVisible.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToBeVisible.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.NotToContainText
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs: python
The opposite of [`method: LocatorAssertions.toContainText` ].
### param: LocatorAssertions.NotToContainText.expected
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-22 18:39:10 +01:00
- `expected` < [string]|[RegExp]|[Array]< [string]|[RegExp]>>
2021-10-22 16:56:58 -07:00
Expected substring or RegExp or a list of those.
2022-06-02 05:52:53 -07:00
### option: LocatorAssertions.NotToContainText.ignoreCase
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-06-02 05:52:53 -07:00
- `ignoreCase` < [boolean]>
Whether to perform case-insensitive match. [`option: ignoreCase` ] option takes precedence over the corresponding regular expression flag if specified.
2021-11-18 00:46:30 +01:00
### option: LocatorAssertions.NotToContainText.useInnerText
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
- `useInnerText` < [boolean]>
Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text.
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToContainText.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToContainText.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.NotToHaveAttribute
2022-08-30 17:53:00 -07:00
* since: v1.18
2021-11-18 00:46:30 +01:00
* langs: python
2021-10-22 16:56:58 -07:00
2022-08-30 17:53:00 -07:00
The opposite of [`method: LocatorAssertions.toHaveAttribute#1` ].
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.NotToHaveAttribute.name
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
- `name` < [string]>
Attribute name.
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.NotToHaveAttribute.value
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
- `value` < [string]|[RegExp]>
Expected attribute value.
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToHaveAttribute.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToHaveAttribute.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.NotToHaveClass
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs: python
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
The opposite of [`method: LocatorAssertions.toHaveClass` ].
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.NotToHaveClass.expected
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-22 18:39:10 +01:00
- `expected` < [string]|[RegExp]|[Array]< [string]|[RegExp]>>
2021-10-22 16:56:58 -07:00
Expected class or RegExp or a list of those.
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToHaveClass.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToHaveClass.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.NotToHaveCount
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs: python
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
The opposite of [`method: LocatorAssertions.toHaveCount` ].
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.NotToHaveCount.count
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
- `count` < [int]>
Expected count.
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToHaveCount.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToHaveCount.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.NotToHaveCSS
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs: python
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
The opposite of [`method: LocatorAssertions.toHaveCSS` ].
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.NotToHaveCSS.name
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
- `name` < [string]>
CSS property name.
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.NotToHaveCSS.value
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
- `value` < [string]|[RegExp]>
CSS property value.
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToHaveCSS.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToHaveCSS.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.NotToHaveId
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs: python
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
The opposite of [`method: LocatorAssertions.toHaveId` ].
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.NotToHaveId.id
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
- `id` < [string]|[RegExp]>
2021-10-22 16:56:58 -07:00
Element id.
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToHaveId.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToHaveId.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.NotToHaveJSProperty
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs: python
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
The opposite of [`method: LocatorAssertions.toHaveJSProperty` ].
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.NotToHaveJSProperty.name
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
- `name` < [string]>
Property name.
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.NotToHaveJSProperty.value
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-02-21 14:01:53 +01:00
- `value` < [any]>
2021-10-22 16:56:58 -07:00
Property value.
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToHaveJSProperty.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToHaveJSProperty.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.NotToHaveText
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs: python
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
The opposite of [`method: LocatorAssertions.toHaveText` ].
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.NotToHaveText.expected
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-22 18:39:10 +01:00
- `expected` < [string]|[RegExp]|[Array]< [string]|[RegExp]>>
2021-10-22 16:56:58 -07:00
Expected substring or RegExp or a list of those.
2022-06-02 05:52:53 -07:00
### option: LocatorAssertions.NotToHaveText.ignoreCase
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-06-02 05:52:53 -07:00
- `ignoreCase` < [boolean]>
Whether to perform case-insensitive match. [`option: ignoreCase` ] option takes precedence over the corresponding regular expression flag if specified.
2021-11-18 00:46:30 +01:00
### option: LocatorAssertions.NotToHaveText.useInnerText
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
- `useInnerText` < [boolean]>
Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text.
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToHaveText.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToHaveText.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.NotToHaveValue
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs: python
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
The opposite of [`method: LocatorAssertions.toHaveValue` ].
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.NotToHaveValue.value
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-06-02 16:01:34 -04:00
- `value` < [string]|[RegExp]>
2021-10-22 16:56:58 -07:00
2022-06-02 16:01:34 -04:00
Expected value.
2021-10-22 16:56:58 -07:00
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToHaveValue.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.NotToHaveValue.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
2022-06-02 16:01:34 -04:00
## async method: LocatorAssertions.NotToHaveValues
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-06-02 16:01:34 -04:00
* langs: python
The opposite of [`method: LocatorAssertions.toHaveValues` ].
### param: LocatorAssertions.NotToHaveValues.values
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-06-02 16:01:34 -04:00
- `values` < [Array]< [string]|[RegExp]>>
Expected options currently selected.
### option: LocatorAssertions.NotToHaveValues.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-06-02 16:01:34 -04:00
### option: LocatorAssertions.NotToHaveValues.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2021-11-18 00:46:30 +01:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.toBeChecked
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: isChecked
2021-10-22 16:56:58 -07:00
Ensures the [Locator] points to a checked input.
2021-11-24 21:58:35 +01:00
```js
const locator = page.locator('.subscribe');
await expect(locator).toBeChecked();
```
2021-10-22 16:56:58 -07:00
```java
assertThat(page.locator(".subscribe")).isChecked();
```
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import expect
locator = page.locator(".subscribe")
await expect(locator).to_be_checked()
```
```python sync
from playwright.sync_api import expect
locator = page.locator(".subscribe")
expect(locator).to_be_checked()
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator(".subscribe");
await Expect(locator).ToBeCheckedAsync();
```
2021-12-02 10:31:26 -08:00
### option: LocatorAssertions.toBeChecked.checked
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-12-02 10:31:26 -08:00
- `checked` < [boolean]>
2021-11-18 00:46:30 +01:00
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toBeChecked.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toBeChecked.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2021-10-22 16:56:58 -07:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.toBeDisabled
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: isDisabled
2021-10-22 16:56:58 -07:00
2022-04-18 17:06:01 -07:00
Ensures the [Locator] points to a disabled element. Element is disabled if it has "disabled" attribute
or is disabled via ['aria-disabled' ](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-disabled ).
Note that only native control elements such as HTML `button` , `input` , `select` , `textarea` , `option` , `optgroup`
can be disabled by setting "disabled" attribute. "disabled" attribute on other elements is ignored
by the browser.
2021-10-22 16:56:58 -07:00
2021-11-24 21:58:35 +01:00
```js
const locator = page.locator('button.submit');
await expect(locator).toBeDisabled();
```
2021-10-22 16:56:58 -07:00
```java
assertThat(page.locator("button.submit")).isDisabled();
```
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import expect
locator = page.locator("button.submit")
await expect(locator).to_be_disabled()
```
```python sync
from playwright.sync_api import expect
locator = page.locator("button.submit")
expect(locator).to_be_disabled()
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator("button.submit");
await Expect(locator).ToBeDisabledAsync();
```
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toBeDisabled.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toBeDisabled.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.toBeEditable
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: isEditable
2021-10-22 16:56:58 -07:00
Ensures the [Locator] points to an editable element.
2021-11-24 21:58:35 +01:00
```js
const locator = page.locator('input');
await expect(locator).toBeEditable();
```
2021-10-22 16:56:58 -07:00
```java
assertThat(page.locator("input")).isEditable();
```
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import expect
locator = page.locator(".input")
await expect(locator).to_be_editable()
```
```python sync
from playwright.sync_api import expect
locator = page.locator(".input")
expect(locator).to_be_editable()
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator("input");
await Expect(locator).ToBeEditableAsync();
```
2022-09-06 12:50:45 -07:00
### option: LocatorAssertions.toBeEditable.editable
* since: v1.26
- `editable` < [boolean]>
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toBeEditable.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toBeEditable.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2021-10-22 16:56:58 -07:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.toBeEmpty
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: isEmpty
2021-10-22 16:56:58 -07:00
Ensures the [Locator] points to an empty editable element or to a DOM node that has no text.
2021-11-24 21:58:35 +01:00
```js
const locator = page.locator('div.warning');
await expect(locator).toBeEmpty();
```
2021-10-22 16:56:58 -07:00
```java
assertThat(page.locator("div.warning")).isEmpty();
```
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import expect
locator = page.locator("div.warning")
await expect(locator).to_be_empty()
```
```python sync
from playwright.sync_api import expect
locator = page.locator("div.warning")
expect(locator).to_be_empty()
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator("div.warning");
await Expect(locator).ToBeEmptyAsync();
```
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toBeEmpty.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toBeEmpty.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.toBeEnabled
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: isEnabled
2021-10-22 16:56:58 -07:00
Ensures the [Locator] points to an enabled element.
2021-11-24 21:58:35 +01:00
```js
const locator = page.locator('button.submit');
await expect(locator).toBeEnabled();
```
2021-10-22 16:56:58 -07:00
```java
assertThat(page.locator("button.submit")).isEnabled();
```
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import expect
locator = page.locator("button.submit")
await expect(locator).to_be_enabled()
```
```python sync
from playwright.sync_api import expect
locator = page.locator("button.submit")
expect(locator).to_be_enabled()
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator("button.submit");
await Expect(locator).toBeEnabledAsync();
```
2022-09-06 11:40:34 -07:00
### option: LocatorAssertions.toBeEnabled.enabled
* since: v1.26
- `enabled` < [boolean]>
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toBeEnabled.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toBeEnabled.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2021-10-22 16:56:58 -07:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.toBeFocused
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: isFocused
2021-10-22 16:56:58 -07:00
Ensures the [Locator] points to a focused DOM node.
2021-11-24 21:58:35 +01:00
```js
const locator = page.locator('input');
await expect(locator).toBeFocused();
```
2021-10-22 16:56:58 -07:00
```java
assertThat(page.locator("input")).isFocused();
```
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import expect
locator = page.locator('input')
await expect(locator).to_be_focused()
```
```python sync
from playwright.sync_api import expect
locator = page.locator('input')
expect(locator).to_be_focused()
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator("input");
await Expect(locator).ToBeFocusedAsync();
```
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toBeFocused.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toBeFocused.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.toBeHidden
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: isHidden
2021-10-22 16:56:58 -07:00
2022-09-02 16:36:19 -07:00
Ensures that [Locator] either does not resolve to any DOM node, or resolves to a [non-visible ](./actionability.md#visible ) one.
2021-10-22 16:56:58 -07:00
2021-11-24 21:58:35 +01:00
```js
const locator = page.locator('.my-element');
await expect(locator).toBeHidden();
```
2021-10-22 16:56:58 -07:00
```java
assertThat(page.locator(".my-element")).isHidden();
```
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import expect
locator = page.locator('.my-element')
await expect(locator).to_be_hidden()
```
```python sync
from playwright.sync_api import expect
locator = page.locator('.my-element')
expect(locator).to_be_hidden()
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator(".my-element");
await Expect(locator).ToBeHiddenAsync();
```
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toBeHidden.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toBeHidden.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2021-10-22 16:56:58 -07:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.toBeVisible
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: isVisible
2021-10-22 16:56:58 -07:00
2022-09-02 16:36:19 -07:00
Ensures that [Locator] points to an [attached ](./actionability.md#visible ) and [visible ](./actionability.md#visible ) DOM node.
2021-10-22 16:56:58 -07:00
2021-11-24 21:58:35 +01:00
```js
const locator = page.locator('.my-element');
await expect(locator).toBeVisible();
```
2021-10-22 16:56:58 -07:00
```java
2022-05-09 09:18:19 -07:00
assertThat(page.locator(".my-element")).isVisible();
2021-10-22 16:56:58 -07:00
```
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import expect
locator = page.locator('.my-element')
await expect(locator).to_be_visible()
```
```python sync
from playwright.sync_api import expect
locator = page.locator('.my-element')
expect(locator).to_be_visible()
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator(".my-element");
await Expect(locator).ToBeVisibleAsync();
```
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toBeVisible.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toBeVisible.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-10-22 16:56:58 -07:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.toContainText
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: containsText
2021-10-22 16:56:58 -07:00
2021-11-18 00:46:30 +01:00
Ensures the [Locator] points to an element that contains the given text. You can use regular expressions for the value as well.
2021-10-22 16:56:58 -07:00
2021-11-24 21:58:35 +01:00
```js
const locator = page.locator('.title');
await expect(locator).toContainText('substring');
await expect(locator).toContainText(/\d messages/);
```
2021-10-22 16:56:58 -07:00
```java
2021-11-18 00:46:30 +01:00
assertThat(page.locator(".title")).containsText("substring");
2021-10-22 16:56:58 -07:00
```
2021-11-18 00:46:30 +01:00
2021-11-30 20:04:44 +01:00
```python async
import re
from playwright.async_api import expect
locator = page.locator('.title')
await expect(locator).to_contain_text("substring")
await expect(locator).to_contain_text(re.compile(r"\d messages"))
```
```python sync
import re
from playwright.sync_api import expect
locator = page.locator('.title')
expect(locator).to_contain_text("substring")
expect(locator).to_contain_text(re.compile(r"\d messages"))
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator(".title");
await Expect(locator).ToContainTextAsync("substring");
await Expect(locator).ToContainTextAsync(new Regex("\\d messages"));
```
2022-08-05 10:27:17 -07:00
If you pass an array as an expected value, the expectations are:
1. Locator resolves to a list of elements.
1. Elements from a **subset** of this list contain text from the expected array, respectively.
1. The matching subset of elements has the same order as the expected array.
1. Each text value from the expected array is matched by some element from the list.
For example, consider the following list:
```html
< ul >
< li > Item Text 1< / li >
< li > Item Text 2< / li >
< li > Item Text 3< / li >
< / ul >
```
Let's see how we can use the assertion:
2021-11-18 00:46:30 +01:00
2021-11-24 21:58:35 +01:00
```js
2022-08-05 10:27:17 -07:00
// ✓ Contains the right items in the right order
await expect(page.locator('ul > li')).toContainText(['Text 1', 'Text 3']);
// ✖ Wrong order
await expect(page.locator('ul > li')).toContainText(['Text 3', 'Text 2']);
// ✖ No item contains this text
await expect(page.locator('ul > li')).toContainText(['Some 33']);
// ✖ Locator points to the outer list element, not to the list items
await expect(page.locator('ul')).toContainText(['Text 3']);
2021-11-24 21:58:35 +01:00
```
2021-11-18 00:46:30 +01:00
```java
2022-08-05 10:27:17 -07:00
// ✓ Contains the right items in the right order
assertThat(page.locator("ul > li")).containsText(new String[] {"Text 1", "Text 3", "Text 4"});
// ✖ Wrong order
assertThat(page.locator("ul > li")).containsText(new String[] {"Text 3", "Text 2"});
// ✖ No item contains this text
assertThat(page.locator("ul > li")).containsText(new String[] {"Some 33"});
// ✖ Locator points to the outer list element, not to the list items
assertThat(page.locator("ul")).containsText(new String[] {"Text 3"});
2021-11-18 00:46:30 +01:00
```
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import expect
2022-08-05 10:27:17 -07:00
# ✓ Contains the right items in the right order
await expect(page.locator("ul > li")).to_contain_text(["Text 1", "Text 3", "Text 4"])
# ✖ Wrong order
await expect(page.locator("ul > li")).to_contain_text(["Text 3", "Text 2"])
# ✖ No item contains this text
await expect(page.locator("ul > li")).to_contain_text(["Some 33"])
# ✖ Locator points to the outer list element, not to the list items
await expect(page.locator("ul")).to_contain_text(["Text 3"])
2021-11-30 20:04:44 +01:00
```
```python sync
from playwright.sync_api import expect
2022-08-05 10:27:17 -07:00
# ✓ Contains the right items in the right order
expect(page.locator("ul > li")).to_contain_text(["Text 1", "Text 3", "Text 4"])
# ✖ Wrong order
expect(page.locator("ul > li")).to_contain_text(["Text 3", "Text 2"])
# ✖ No item contains this text
expect(page.locator("ul > li")).to_contain_text(["Some 33"])
# ✖ Locator points to the outer list element, not to the list items
expect(page.locator("ul")).to_contain_text(["Text 3"])
2021-11-30 20:04:44 +01:00
```
2022-02-21 14:01:53 +01:00
```csharp
2022-08-05 10:27:17 -07:00
// ✓ Contains the right items in the right order
await Expect(Page.Locator("ul > li")).ToContainTextAsync(new string[] {"Text 1", "Text 3", "Text 4"});
// ✖ Wrong order
await Expect(Page.Locator("ul > li")).ToContainTextAsync(new string[] {"Text 3", "Text 2"});
// ✖ No item contains this text
await Expect(Page.Locator("ul > li")).ToContainTextAsync(new string[] {"Some 33"});
// ✖ Locator points to the outer list element, not to the list items
await Expect(Page.Locator("ul")).ToContainTextAsync(new string[] {"Text 3"});
2022-02-21 14:01:53 +01:00
```
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.toContainText.expected
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-24 21:58:35 +01:00
* langs: python, js
2021-11-22 18:39:10 +01:00
- `expected` < [string]|[RegExp]|[Array]< [string]|[RegExp]>>
Expected substring or RegExp or a list of those.
### param: LocatorAssertions.toContainText.expected
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-02-21 14:01:53 +01:00
* langs: java, csharp
2021-11-18 00:46:30 +01:00
- `expected` < [string]|[RegExp]|[Array]< [string]>|[Array]< [RegExp]>>
Expected substring or RegExp or a list of those.
2022-06-02 05:52:53 -07:00
### option: LocatorAssertions.toContainText.ignoreCase
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-06-02 05:52:53 -07:00
- `ignoreCase` < [boolean]>
Whether to perform case-insensitive match. [`option: ignoreCase` ] option takes precedence over the corresponding regular expression flag if specified.
2021-11-18 00:46:30 +01:00
### option: LocatorAssertions.toContainText.useInnerText
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
- `useInnerText` < [boolean]>
Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text.
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toContainText.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toContainText.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2022-08-30 17:53:00 -07:00
## async method: LocatorAssertions.toHaveAttribute#1
* since: v1.18
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: hasAttribute
2022-08-30 17:53:00 -07:00
Ensures the [Locator] points to an element with given attribute value.
2021-11-18 00:46:30 +01:00
2021-11-24 21:58:35 +01:00
```js
const locator = page.locator('input');
2022-08-25 05:28:34 -07:00
// Assert attribute with given value.
2021-11-24 21:58:35 +01:00
await expect(locator).toHaveAttribute('type', 'text');
```
2021-11-18 00:46:30 +01:00
```java
assertThat(page.locator("input")).hasAttribute("type", "text");
```
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import expect
locator = page.locator("input")
await expect(locator).to_have_attribute("type", "text")
```
```python sync
from playwright.sync_api import expect
locator = page.locator("input")
expect(locator).to_have_attribute("type", "text")
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator("input");
await Expect(locator).ToHaveAttributeAsync("type", "text");
```
2022-08-30 17:53:00 -07:00
### param: LocatorAssertions.toHaveAttribute#1.name
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
- `name` < [string]>
Attribute name.
2022-08-30 17:53:00 -07:00
### param: LocatorAssertions.toHaveAttribute#1.value
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-08-30 17:53:00 -07:00
- `value` < [string]|[RegExp]>
2021-11-18 00:46:30 +01:00
2022-08-30 17:53:00 -07:00
Expected attribute value.
2021-11-18 00:46:30 +01:00
2022-08-30 17:53:00 -07:00
### option: LocatorAssertions.toHaveAttribute#1.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-08-30 17:53:00 -07:00
### option: LocatorAssertions.toHaveAttribute#1.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2022-08-30 17:53:00 -07:00
## async method: LocatorAssertions.toHaveAttribute#2
* since: v1.26
* langs:
- alias-java: hasAttribute
Ensures the [Locator] points to an element with given attribute. The method will assert attribute
presence.
```js
const locator = page.locator('input');
// Assert attribute existance.
await expect(locator).toHaveAttribute('disabled');
await expect(locator).not.toHaveAttribute('open');
```
```java
assertThat(page.locator("input")).hasAttribute("disabled");
assertThat(page.locator("input")).not().hasAttribute("open");
```
```python async
from playwright.async_api import expect
locator = page.locator("input")
await expect(locator).to_have_attribute("disabled")
await expect(locator).not_to_have_attribute("open")
```
```python sync
from playwright.sync_api import expect
locator = page.locator("input")
expect(locator).to_have_attribute("disabled")
expect(locator).not_to_have_attribute("open")
```
```csharp
var locator = Page.Locator("input");
await Expect(locator).ToHaveAttributeAsync("disabled");
await Expect(locator).Not.ToHaveAttributeAsync("open");
```
### param: LocatorAssertions.toHaveAttribute#2.name
* since: v1.26
- `name` < [string]>
Attribute name.
### option: LocatorAssertions.toHaveAttribute#2.timeout = %%-js-assertions-timeout-%%
* since: v1.26
### option: LocatorAssertions.toHaveAttribute#2.timeout = %%-csharp-java-python-assertions-timeout-%%
* since: v1.26
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.toHaveClass
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: hasClass
2022-07-12 23:17:10 +02:00
Ensures the [Locator] points to an element with given CSS classes. This needs to be a full match
2022-07-14 22:03:37 +02:00
or using a relaxed regular expression.
2022-07-12 23:17:10 +02:00
```html
< div class = 'selected row' id = 'component' > < / div >
```
2021-11-18 00:46:30 +01:00
2021-11-24 21:58:35 +01:00
```js
const locator = page.locator('#component ');
await expect(locator).toHaveClass(/selected/);
2022-07-12 23:17:10 +02:00
await expect(locator).toHaveClass('selected row');
2021-11-24 21:58:35 +01:00
```
2021-11-18 00:46:30 +01:00
```java
assertThat(page.locator("#component ")).hasClass(Pattern.compile("selected"));
2022-07-12 23:17:10 +02:00
assertThat(page.locator("#component ")).hasClass("selected row");
2021-11-18 00:46:30 +01:00
```
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import expect
locator = page.locator("#component ")
await expect(locator).to_have_class(re.compile(r"selected"))
2022-07-12 23:17:10 +02:00
await expect(locator).to_have_class("selected row")
2021-11-30 20:04:44 +01:00
```
```python sync
from playwright.sync_api import expect
locator = page.locator("#component ")
expect(locator).to_have_class(re.compile(r"selected"))
2022-07-12 23:17:10 +02:00
expect(locator).to_have_class("selected row")
2021-11-30 20:04:44 +01:00
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator("#component ");
await Expect(locator).ToHaveClassAsync(new Regex("selected"));
2022-07-12 23:17:10 +02:00
await Expect(locator).ToHaveClassAsync("selected row");
2022-02-21 14:01:53 +01:00
```
2022-01-07 09:13:46 -08:00
Note that if array is passed as an expected value, entire lists of elements can be asserted:
2021-11-18 00:46:30 +01:00
2021-11-24 21:58:35 +01:00
```js
const locator = page.locator('list > .component');
await expect(locator).toHaveClass(['component', 'component selected', 'component']);
```
2021-11-18 00:46:30 +01:00
```java
assertThat(page.locator("list > .component")).hasClass(new String[] {"component", "component selected", "component"});
```
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import expect
locator = page.locator("list > .component")
await expect(locator).to_have_class(["component", "component selected", "component"])
```
```python sync
from playwright.sync_api import expect
locator = page.locator("list > .component")
expect(locator).to_have_class(["component", "component selected", "component"])
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator("list > .component");
await Expect(locator).ToHaveClassAsync(new string[]{"component", "component selected", "component"});
```
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.toHaveClass.expected
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-24 21:58:35 +01:00
* langs: python, js
2021-11-22 18:39:10 +01:00
- `expected` < [string]|[RegExp]|[Array]< [string]|[RegExp]>>
Expected class or RegExp or a list of those.
### param: LocatorAssertions.toHaveClass.expected
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-02-21 14:01:53 +01:00
* langs: java, csharp
2021-11-18 00:46:30 +01:00
- `expected` < [string]|[RegExp]|[Array]< [string]>|[Array]< [RegExp]>>
Expected class or RegExp or a list of those.
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toHaveClass.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toHaveClass.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.toHaveCount
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: hasCount
Ensures the [Locator] resolves to an exact number of DOM nodes.
2021-11-24 21:58:35 +01:00
```js
const list = page.locator('list > .component');
await expect(list).toHaveCount(3);
```
2021-11-18 00:46:30 +01:00
```java
assertThat(page.locator("list > .component")).hasCount(3);
```
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import expect
locator = page.locator("list > .component")
await expect(locator).to_have_count(3)
```
```python sync
from playwright.sync_api import expect
locator = page.locator("list > .component")
expect(locator).to_have_count(3)
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator("list > .component");
await Expect(locator).ToHaveCountAsync(3);
```
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.toHaveCount.count
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
- `count` < [int]>
Expected count.
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toHaveCount.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toHaveCount.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.toHaveCSS
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: hasCSS
Ensures the [Locator] resolves to an element with the given computed CSS style.
2021-11-24 21:58:35 +01:00
```js
const locator = page.locator('button');
await expect(locator).toHaveCSS('display', 'flex');
```
2021-11-18 00:46:30 +01:00
```java
assertThat(page.locator("button")).hasCSS("display", "flex");
```
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import expect
locator = page.locator("button")
await expect(locator).to_have_css("display", "flex")
```
```python sync
from playwright.sync_api import expect
locator = page.locator("button")
expect(locator).to_have_css("display", "flex")
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator("button");
await Expect(locator).ToHaveCSSAsync("display", "flex");
```
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.toHaveCSS.name
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
- `name` < [string]>
CSS property name.
### param: LocatorAssertions.toHaveCSS.value
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
- `value` < [string]|[RegExp]>
CSS property value.
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toHaveCSS.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toHaveCSS.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.toHaveId
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: hasId
Ensures the [Locator] points to an element with the given DOM Node ID.
2021-11-24 21:58:35 +01:00
```js
const locator = page.locator('input');
await expect(locator).toHaveId('lastname');
```
2021-11-18 00:46:30 +01:00
```java
assertThat(page.locator("input")).hasId("lastname");
```
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import expect
locator = page.locator("input")
await expect(locator).to_have_id("lastname")
```
```python sync
from playwright.sync_api import expect
locator = page.locator("input")
expect(locator).to_have_id("lastname")
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator("input");
await Expect(locator).ToHaveIdAsync("lastname");
```
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.toHaveId.id
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
- `id` < [string]|[RegExp]>
Element id.
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toHaveId.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toHaveId.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.toHaveJSProperty
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: hasJSProperty
2021-11-24 21:58:35 +01:00
Ensures the [Locator] points to an element with given JavaScript property. Note that this property can be
of a primitive type as well as a plain serializable JavaScript object.
```js
const locator = page.locator('.component');
await expect(locator).toHaveJSProperty('loaded', true);
```
2021-11-18 00:46:30 +01:00
```java
2021-11-30 20:04:44 +01:00
assertThat(page.locator("input")).hasJSProperty("loaded", true);
```
```python async
from playwright.async_api import expect
locator = page.locator(".component")
await expect(locator).to_have_js_property("loaded", True)
```
```python sync
from playwright.sync_api import expect
locator = page.locator(".component")
expect(locator).to_have_js_property("loaded", True)
2021-11-18 00:46:30 +01:00
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator(".component");
await Expect(locator).ToHaveJSPropertyAsync("loaded", true);
```
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.toHaveJSProperty.name
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
- `name` < [string]>
Property name.
### param: LocatorAssertions.toHaveJSProperty.value
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-02-21 14:01:53 +01:00
- `value` < [any]>
2021-11-18 00:46:30 +01:00
Property value.
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toHaveJSProperty.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toHaveJSProperty.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2022-04-14 13:22:42 -07:00
2022-05-16 06:53:46 -08:00
## async method: LocatorAssertions.toHaveScreenshot#1
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-04-14 13:22:42 -07:00
* langs: js
2022-05-24 11:54:32 -06:00
This function will wait until two consecutive locator screenshots
yield the same result, and then compare the last screenshot with the expectation.
2022-04-14 13:22:42 -07:00
```js
const locator = page.locator('button');
2022-05-16 06:53:46 -08:00
await expect(locator).toHaveScreenshot('image.png');
2022-04-14 13:22:42 -07:00
```
2022-05-16 06:53:46 -08:00
### param: LocatorAssertions.toHaveScreenshot#1.name
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 06:53:46 -08:00
- `name` < [string]|[Array]< [string]>>
2022-04-14 13:22:42 -07:00
2022-05-16 06:53:46 -08:00
Snapshot name.
2022-04-14 13:22:42 -07:00
2022-05-16 06:53:46 -08:00
### option: LocatorAssertions.toHaveScreenshot#1.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 22:26:23 +03:00
### option: LocatorAssertions.toHaveScreenshot#1.animations = %%-screenshot-option-animations-default-disabled-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 22:26:23 +03:00
2022-05-16 06:53:46 -08:00
### option: LocatorAssertions.toHaveScreenshot#1.caret = %%-screenshot-option-caret-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 06:53:46 -08:00
### option: LocatorAssertions.toHaveScreenshot#1.mask = %%-screenshot-option-mask-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 06:53:46 -08:00
### option: LocatorAssertions.toHaveScreenshot#1.omitBackground = %%-screenshot-option-omit-background-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 22:26:23 +03:00
### option: LocatorAssertions.toHaveScreenshot#1.scale = %%-screenshot-option-scale-default-css-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 06:53:46 -08:00
### option: LocatorAssertions.toHaveScreenshot#1.maxDiffPixels = %%-assertions-max-diff-pixels-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 06:53:46 -08:00
### option: LocatorAssertions.toHaveScreenshot#1.maxDiffPixelRatio = %%-assertions-max-diff-pixel-ratio-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 06:53:46 -08:00
### option: LocatorAssertions.toHaveScreenshot#1.threshold = %%-assertions-threshold-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-04-14 13:22:42 -07:00
2022-05-16 06:53:46 -08:00
## async method: LocatorAssertions.toHaveScreenshot#2
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 06:53:46 -08:00
* langs: js
2022-04-14 13:22:42 -07:00
2022-05-24 11:54:32 -06:00
This function will wait until two consecutive locator screenshots
yield the same result, and then compare the last screenshot with the expectation.
2022-04-14 13:22:42 -07:00
2022-05-16 06:53:46 -08:00
```js
const locator = page.locator('button');
await expect(locator).toHaveScreenshot();
```
2022-04-14 13:22:42 -07:00
2022-05-16 06:53:46 -08:00
### option: LocatorAssertions.toHaveScreenshot#2.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 22:26:23 +03:00
### option: LocatorAssertions.toHaveScreenshot#2.animations = %%-screenshot-option-animations-default-disabled-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 22:26:23 +03:00
2022-05-16 06:53:46 -08:00
### option: LocatorAssertions.toHaveScreenshot#2.caret = %%-screenshot-option-caret-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 06:53:46 -08:00
### option: LocatorAssertions.toHaveScreenshot#2.mask = %%-screenshot-option-mask-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 06:53:46 -08:00
### option: LocatorAssertions.toHaveScreenshot#2.omitBackground = %%-screenshot-option-omit-background-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 22:26:23 +03:00
### option: LocatorAssertions.toHaveScreenshot#2.scale = %%-screenshot-option-scale-default-css-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 06:53:46 -08:00
### option: LocatorAssertions.toHaveScreenshot#2.maxDiffPixels = %%-assertions-max-diff-pixels-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 06:53:46 -08:00
### option: LocatorAssertions.toHaveScreenshot#2.maxDiffPixelRatio = %%-assertions-max-diff-pixel-ratio-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-05-16 06:53:46 -08:00
### option: LocatorAssertions.toHaveScreenshot#2.threshold = %%-assertions-threshold-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-04-14 13:22:42 -07:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.toHaveText
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: hasText
Ensures the [Locator] points to an element with the given text. You can use regular expressions for the value as well.
2021-11-24 21:58:35 +01:00
```js
const locator = page.locator('.title');
await expect(locator).toHaveText(/Welcome, Test User/);
await expect(locator).toHaveText(/Welcome, .*/);
```
2021-11-18 00:46:30 +01:00
```java
assertThat(page.locator(".title")).hasText("Welcome, Test User");
assertThat(page.locator(".title")).hasText(Pattern.compile("Welcome, .*"));
```
2021-11-30 20:04:44 +01:00
```python async
import re
from playwright.async_api import expect
locator = page.locator(".title")
await expect(locator).to_have_text(re.compile(r"Welcome, Test User"))
await expect(locator).to_have_text(re.compile(r"Welcome, .*"))
```
```python sync
import re
from playwright.sync_api import expect
locator = page.locator(".title")
expect(locator).to_have_text(re.compile(r"Welcome, Test User"))
expect(locator).to_have_text(re.compile(r"Welcome, .*"))
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator(".title");
await Expect(locator).ToHaveTextAsync(new Regex("Welcome, Test User"));
await Expect(locator).ToHaveTextAsync(new Regex("Welcome, .*"));
```
2022-08-05 10:27:17 -07:00
If you pass an array as an expected value, the expectations are:
1. Locator resolves to a list of elements.
1. The number of elements equals the number of expected values in the array.
1. Elements from the list have text matching expected array values, one by one, in order.
For example, consider the following list:
```html
< ul >
< li > Text 1< / li >
< li > Text 2< / li >
< li > Text 3< / li >
< / ul >
```
Let's see how we can use the assertion:
2021-11-18 00:46:30 +01:00
2021-11-24 21:58:35 +01:00
```js
2022-08-05 10:27:17 -07:00
// ✓ Has the right items in the right order
await expect(page.locator('ul > li')).toHaveText(['Text 1', 'Text 2', 'Text 3']);
// ✖ Wrong order
await expect(page.locator('ul > li')).toHaveText(['Text 3', 'Text 2', 'Text 1']);
// ✖ Last item does not match
await expect(page.locator('ul > li')).toHaveText(['Text 1', 'Text 2', 'Text']);
// ✖ Locator points to the outer list element, not to the list items
await expect(page.locator('ul')).toHaveText(['Text 1', 'Text 2', 'Text 3']);
2021-11-24 21:58:35 +01:00
```
2021-11-18 00:46:30 +01:00
```java
2022-08-05 10:27:17 -07:00
// ✓ Has the right items in the right order
assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
// ✖ Wrong order
assertThat(page.locator("ul > li")).hasText(new String[] {"Text 3", "Text 2", "Text 1"});
// ✖ Last item does not match
assertThat(page.locator("ul > li")).hasText(new String[] {"Text 1", "Text 2", "Text"});
// ✖ Locator points to the outer list element, not to the list items
assertThat(page.locator("ul")).hasText(new String[] {"Text 1", "Text 2", "Text 3"});
2021-11-18 00:46:30 +01:00
```
2021-11-30 20:04:44 +01:00
```python async
from playwright.async_api import expect
2022-08-05 10:27:17 -07:00
# ✓ Has the right items in the right order
await expect(page.locator("ul > li")).to_have_text(["Text 1", "Text 2", "Text 3"])
# ✖ Wrong order
await expect(page.locator("ul > li")).to_have_text(["Text 3", "Text 2", "Text 1"])
# ✖ Last item does not match
await expect(page.locator("ul > li")).to_have_text(["Text 1", "Text 2", "Text"])
# ✖ Locator points to the outer list element, not to the list items
await expect(page.locator("ul")).to_have_text(["Text 1", "Text 2", "Text 3"])
2021-11-30 20:04:44 +01:00
```
```python sync
from playwright.sync_api import expect
2022-08-05 10:27:17 -07:00
# ✓ Has the right items in the right order
await expect(page.locator("ul > li")).to_have_text(["Text 1", "Text 2", "Text 3"])
# ✖ Wrong order
await expect(page.locator("ul > li")).to_have_text(["Text 3", "Text 2", "Text 1"])
# ✖ Last item does not match
await expect(page.locator("ul > li")).to_have_text(["Text 1", "Text 2", "Text"])
# ✖ Locator points to the outer list element, not to the list items
await expect(page.locator("ul")).to_have_text(["Text 1", "Text 2", "Text 3"])
2021-11-30 20:04:44 +01:00
```
2022-02-21 14:01:53 +01:00
```csharp
2022-08-05 10:27:17 -07:00
// ✓ Has the right items in the right order
await Expect(Page.Locator("ul > li")).ToHaveTextAsync(new string[] {"Text 1", "Text 2", "Text 3"});
// ✖ Wrong order
await Expect(Page.Locator("ul > li")).ToHaveTextAsync(new string[] {"Text 3", "Text 2", "Text 1"});
// ✖ Last item does not match
await Expect(Page.Locator("ul > li")).ToHaveTextAsync(new string[] {"Text 1", "Text 2", "Text"});
// ✖ Locator points to the outer list element, not to the list items
await Expect(Page.Locator("ul")).ToHaveTextAsync(new string[] {"Text 1", "Text 2", "Text 3"});
2022-02-21 14:01:53 +01:00
```
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.toHaveText.expected
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-24 21:58:35 +01:00
* langs: python, js
2021-11-22 18:39:10 +01:00
- `expected` < [string]|[RegExp]|[Array]< [string]|[RegExp]>>
Expected substring or RegExp or a list of those.
### param: LocatorAssertions.toHaveText.expected
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-02-21 14:01:53 +01:00
* langs: java, csharp
2021-11-18 00:46:30 +01:00
- `expected` < [string]|[RegExp]|[Array]< [string]>|[Array]< [RegExp]>>
Expected substring or RegExp or a list of those.
2022-06-02 05:52:53 -07:00
### option: LocatorAssertions.toHaveText.ignoreCase
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-06-02 05:52:53 -07:00
- `ignoreCase` < [boolean]>
Whether to perform case-insensitive match. [`option: ignoreCase` ] option takes precedence over the corresponding regular expression flag if specified.
2021-11-18 00:46:30 +01:00
### option: LocatorAssertions.toHaveText.useInnerText
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
- `useInnerText` < [boolean]>
Whether to use `element.innerText` instead of `element.textContent` when retrieving DOM node text.
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toHaveText.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toHaveText.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2021-11-18 00:46:30 +01:00
2022-02-21 14:01:53 +01:00
## async method: LocatorAssertions.toHaveValue
2022-07-05 16:24:50 -08:00
* since: v1.20
2021-11-18 00:46:30 +01:00
* langs:
- alias-java: hasValue
Ensures the [Locator] points to an element with the given input value. You can use regular expressions for the value as well.
2021-11-24 21:58:35 +01:00
```js
const locator = page.locator('input[type=number]');
await expect(locator).toHaveValue(/[0-9]/);
```
2021-11-18 00:46:30 +01:00
```java
assertThat(page.locator("input[type=number]")).hasValue(Pattern.compile("[0-9]"));
```
2021-11-30 20:04:44 +01:00
```python async
import re
from playwright.async_api import expect
locator = page.locator("input[type=number]")
await expect(locator).to_have_value(re.compile(r"[0-9]"))
```
```python sync
import re
from playwright.sync_api import expect
locator = page.locator("input[type=number]")
expect(locator).to_have_value(re.compile(r"[0-9]"))
```
2022-02-21 14:01:53 +01:00
```csharp
var locator = Page.Locator("input[type=number]");
await Expect(locator).ToHaveValueAsync(new Regex("[0-9]"));
```
2021-11-18 00:46:30 +01:00
### param: LocatorAssertions.toHaveValue.value
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-06-02 16:01:34 -04:00
- `value` < [string]|[RegExp]>
2021-11-18 00:46:30 +01:00
2022-06-02 16:01:34 -04:00
Expected value.
2021-11-18 00:46:30 +01:00
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toHaveValue.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-03-02 12:43:16 -08:00
### option: LocatorAssertions.toHaveValue.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.18
2022-06-02 16:01:34 -04:00
## async method: LocatorAssertions.toHaveValues
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-06-02 16:01:34 -04:00
* langs:
- alias-java: hasValues
Ensures the [Locator] points to multi-select/combobox (i.e. a `select` with the `multiple` attribute) and the specified values are selected.
For example, given the following element:
```html
< select id = "favorite-colors" multiple >
< option value = "R" > Red< / option >
< option value = "G" > Green< / option >
< option value = "B" > Blue< / option >
< / select >
```
```js
const locator = page.locator("id=favorite-colors");
await locator.selectOption(["R", "G"]);
await expect(locator).toHaveValues([/R/, /G/]);
```
```java
page.locator("id=favorite-colors").selectOption(["R", "G"]);
assertThat(page.locator("id=favorite-colors")).hasValues(new Pattern[] { Pattern.compile("R"), Pattern.compile("G") });
```
```python async
import re
from playwright.async_api import expect
locator = page.locator("id=favorite-colors")
await locator.select_option(["R", "G"])
await expect(locator).to_have_values([re.compile(r"R"), re.compile(r"G")])
```
```python sync
import re
from playwright.sync_api import expect
locator = page.locator("id=favorite-colors")
locator.select_option(["R", "G"])
expect(locator).to_have_values([re.compile(r"R"), re.compile(r"G")])
```
```csharp
var locator = Page.Locator("id=favorite-colors");
await locator.SelectOptionAsync(new string[] { "R", "G" })
await Expect(locator).ToHaveValuesAsync(new Regex[] { new Regex("R"), new Regex("G") });
```
### param: LocatorAssertions.toHaveValues.values
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-06-10 16:34:56 -07:00
* langs: python, js
2022-06-02 16:01:34 -04:00
- `values` < [Array]< [string]|[RegExp]>>
Expected options currently selected.
2022-06-10 16:34:56 -07:00
### param: LocatorAssertions.toHaveValues.values
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-06-10 16:34:56 -07:00
* langs: java, csharp
- `values` < [Array]< [string]>|[Array]< [RegExp]>>
Expected options currently selected.
2022-06-02 16:01:34 -04:00
### option: LocatorAssertions.toHaveValues.timeout = %%-js-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.23
2022-06-02 16:01:34 -04:00
### option: LocatorAssertions.toHaveValues.timeout = %%-csharp-java-python-assertions-timeout-%%
2022-07-05 16:24:50 -08:00
* since: v1.23