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
TheelementsLocator object configures how elements are targeted:
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
Text Extraction with Session
Filtered Text Extraction
Chained Locator
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
UsecontinueWith for nested searches:
Returns Array
The command returns an array of text content from all matching elements: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
Multiple Elements
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 - Open browser before extraction
- Get Attributes - Extract attributes instead of text
- Parse Commands - Parse extracted text content