I.getText

Get the text content of an element

Usage

I.getText(target)
Parameter Type Remarks
target string CSS selector or XPATH of the element to extract the text content from

Returns: Text from the target element if found.

Example

HTML

<div id="message">Welcome</div>
<div id="secret">Batman</div>
<div>
    <label for="secret_message">Secret Message</label>
    <input id="secret_message" type="text"/>
</div>

Script

// Extract text from elements
var message = I.getText("#message"); // extracts "Welcome"
var secret = I.getText("#secret"); // extracts "Batman"

// Use the extracted text in later commands
// For example, enter "Welcome Batman" to the "Secret Message" text field
I.fill("Secret Message", message + ' ' + secret);