Get text from a page element

I.getText

Get the text content of an element

Aliases: I.grabText (legacy)

Usage

I.getText(target)

Parameters

ParameterTypeRemarks
targetstringCSS selector or XPATH of the element to extract the text content from

Example(s)

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);

Last Updated: