> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bringits.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get Text Contents

> Extract text content from DOM elements

The Get Text Contents command (GetTextContentsCommand) enables you to extract text content from DOM elements using CSS selectors. This command is essential for extracting visible text content from web pages.

## Overview

The Get Text Contents command provides functionality for:

* Extracting text content from DOM elements
* Using CSS selectors to target elements
* Filtering elements by various criteria
* Chaining locators for nested searches
* Returning arrays of text content from multiple elements

## Parameters

| Parameter           | Type   | Description                         | Required |
| ------------------- | ------ | ----------------------------------- | -------- |
| **elementsLocator** | object | Element locator configuration       | Yes      |
| **sessionId**       | string | Browser session identifier          | No       |
| **key**             | string | Key name for storing extracted text | Yes      |

## Element Locator Configuration

The `elementsLocator` object configures how elements are targeted:

```json theme={null}
{
  "elementsLocator": {
    "selector": ".article-title",
    "timeout": 10000
  }
}
```

### Locator Properties

| Property         | Type   | Description                                     | Required |
| ---------------- | ------ | ----------------------------------------------- | -------- |
| **selector**     | string | CSS selector for element targeting              | Yes      |
| **timeout**      | number | Maximum wait time in milliseconds               | No       |
| **filter**       | object | Filter criteria (innerText, hasChildren, index) | No       |
| **continueWith** | object | Chained locator for nested searches             | No       |

## Usage Examples

### Basic Text Extraction

```json theme={null}
{
  "command": "GetTextContents",
  "params": {
    "elementsLocator": {
      "selector": ".article-title",
      "timeout": 10000
    },
    "key": "article_titles"
  }
}
```

### Text Extraction with Session

```json theme={null}
{
  "command": "GetTextContents",
  "params": {
    "sessionId": "#{UUID}",
    "elementsLocator": {
      "selector": ".article-title",
      "timeout": 10000
    },
    "key": "article_titles"
  }
}
```

### Filtered Text Extraction

```json theme={null}
{
  "command": "GetTextContents",
  "params": {
    "elementsLocator": {
      "selector": ".article-title",
      "timeout": 10000,
      "filter": {
        "innerText": "Example",
        "hasChildren": false
      }
    },
    "key": "filtered_titles"
  }
}
```

### Chained Locator

```json theme={null}
{
  "command": "GetTextContents",
  "params": {
    "elementsLocator": {
      "selector": ".article",
      "timeout": 10000,
      "continueWith": {
        "selector": ".title"
      }
    },
    "key": "nested_titles"
  }
}
```

## Features

### CSS Selectors

Target elements using standard CSS selectors:

* **Class selectors**: `.class-name`
* **ID selectors**: `#element-id`
* **Attribute selectors**: `[data-attribute="value"]`
* **Descendant selectors**: `.parent .child`
* **Pseudo-selectors**: `:first-child`, `:nth-child(n)`

### Filtering

Filter elements by various criteria:

* **innerText**: Filter by text content
* **hasChildren**: Filter by presence of child elements
* **index**: Filter by element index

### Chained Locators

Use `continueWith` for nested searches:

```json theme={null}
{
  "elementsLocator": {
    "selector": ".article",
    "continueWith": {
      "selector": ".title"
    }
  }
}
```

### Returns Array

The command returns an array of text content from all matching elements:

```json theme={null}
{
  "article_titles": [
    "Title 1",
    "Title 2",
    "Title 3"
  ]
}
```

## Variable Support

The Get Text Contents command supports variable interpolation in:

* **Selector**: Use variables in CSS selectors
* **Session ID**: Use `#{UUID}` for session tracking

## Output Structure

The command stores extracted text under the specified key:

### Single Element

```json theme={null}
{
  "article_title": "Example Title"
}
```

### Multiple Elements

```json theme={null}
{
  "article_titles": [
    "Title 1",
    "Title 2",
    "Title 3"
  ]
}
```

## Best Practices

* **Use Stable Selectors**: Prefer class names and IDs over text-based selectors
* **Set Appropriate Timeouts**: Configure timeouts for dynamic content loading
* **Wait for Elements**: Ensure elements are loaded before extraction
* **Handle Empty Results**: Account for cases where no elements match
* **Use Descriptive Keys**: Use clear, descriptive key names for extracted text

## Common Use Cases

* **Content Extraction**: Extract text content from web pages
* **List Extraction**: Extract text from lists and arrays
* **Title Extraction**: Extract titles and headings
* **Description Extraction**: Extract descriptions and summaries

## Related Commands

* [Browser Open](/stream/commands/browser/browser-open) - Open browser before extraction
* [Get Attributes](/stream/commands/browser/get-attributes) - Extract attributes instead of text
* [Parse Commands](/stream/commands/parse) - Parse extracted text content
