<commit_before>---
id: assertions
title: "Assertions"
---

Playwright provides convenience APIs for common tasks, like reading the
text content of an element. These APIs can be used in your test assertions.

<!-- TOC -->


## Text content

```js
const content = await page.textContent('nav:first-child');
expect(content).toBe('home');
```

```python async
content = await page.text_content("nav:first-child")
assert content == "home"
```

```python sync
content = page.text_content("nav:first-child")
assert content == "home"
```

### API reference
- [`method: Page.innerText`]
- [`method: ElementHandle.innerText`]

## Inner text

```js
const text = await page.innerText('.selected');
expect(text).toBe('value');
```

```python async
text = await page.inner_text(".selected")
assert text == "value"
```

```python sync
text = page.inner_text(".selected")
assert text == "value"
```

### API reference
- [`method: Page.innerText`]
- [`method: ElementHandle.innerText`]

## Attribute value

```js
const alt = await page.getAttribute('input', 'alt');
expect(alt).toBe('Text');
```

```python async
checked = await page.get_attribute("input", "alt")<commit_msg>docs(api): fix api reference links for textContent (#5498)<commit_after>---
id: assertions
title: "Assertions"
---

Playwright provides convenience APIs for common tasks, like reading the
text content of an element. These APIs can be used in your test assertions.

<!-- TOC -->


## Text content

```js
const content = await page.textContent('nav:first-child');
expect(content).toBe('home');
```

```python async
content = await page.text_content("nav:first-child")
assert content == "home"
```

```python sync
content = page.text_content("nav:first-child")
assert content == "home"
```

### API reference
- [`method: Page.textContent`]
- [`method: ElementHandle.textContent`]

## Inner text

```js
const text = await page.innerText('.selected');
expect(text).toBe('value');
```

```python async
text = await page.inner_text(".selected")
assert text == "value"
```

```python sync
text = page.inner_text(".selected")
assert text == "value"
```

### API reference
- [`method: Page.innerText`]
- [`method: ElementHandle.innerText`]

## Attribute value

```js
const alt = await page.getAttribute('input', 'alt');
expect(alt).toBe('Text');
```

```python async
checked = await page.get_attribute("input", "alt")
{'fraction_non_alphanumeric': 0.1835095137420719, 'fraction_numerical': 0.0016913319238900633, 'mean_word_length': 5.226315789473684, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5358136', 'n_tokens_mistral': 754, 'n_tokens_neox': 709, 'n_words': 212}