Skip to main content

Retrieve value(s)

Extract information from the page open in a browser session. Use JSON extraction rules to select elements and return named values, or use AI extraction with a query and JSON Schema.

The Advanced selectors option accepts the same locator strings as other web actions. Existing CSS and XPath rules keep their configuration format, including job templates that show the older CSS Selector(s) label.

When to use this action​

What you needExtraction typeConfiguration
Text, attributes, or current form valuesAdvanced selectorsA locator string for each value.
Lists of records or rows from a tableAdvanced selectorsList rules, nested fields, or a table output.
Information described in natural languageAI ExtractionA query and JSON Schema describing the result.

Both extraction types return named values that you can use in downstream Wrk Actions.

Application​

Web - Vision

Inputs (what you have)​

NameDescriptionRequired?
Browser session IDSession returned by Open web session.Yes
Extraction typeAdvanced selectors or AI Extraction. Older configurations may show CSS Selector(s) for selector extraction.Yes
Data extraction rulesJSON object defining the values to extract. See Extraction rule basics.For selector extraction
QueryNatural-language instructions for AI extraction. If omitted, the action asks the AI to follow the supplied schema.No
AI data extraction rulesJSON Schema describing the object the AI should return. See AI extraction.For AI extraction

Inputs can use fixed values or values from the Data Library.

Outputs (what you get)​

NameDescription
Extracted contentThe extracted object serialized as JSON text, such as {"title":"The Wrk Blog"}.
Unsuccessful messageError details when available.
Unsuccessful screenshotA debugging screenshot when available for a browser error.
Custom OutputsNamed values configured from the extracted content.

For example, if Extracted content contains {"title":"The Wrk Blog"}, create a Custom Output named title using the path $.title. See Custom Outputs for choosing a source output and reading nested values.

Outcomes​

NameDescription
SuccessAn extracted object was returned. Its individual fields may still contain missing values.
No resultExtraction returned no object or an empty object, for example when the rules are {}.
Impossible to completeThe action could not complete, for example because it could not connect to the browser session.

A selector that finds no element does not automatically produce No result. For example, {"title":"#missing"} returns {"title":null} as a successful extracted object. Invalid rules and browser-session errors fail the action.

Extraction rule basics​

Enter a JSON object in Data extraction rules. Each top-level key becomes a field in the extracted object.

A CSS or advanced locator string reads the trimmed text of the first matching element. Bare XPath strings retain the behavior described under Lists and nested objects. An object rule lets you choose an output format or extract several matches:

RuleWhat it returns
{"title":"h1"}Text from the first heading.
{"link":{"selector":"a","output":"@href"}}The first link's href attribute.
{"titles":{"selector":"h2","type":"list"}}Text from every matching heading, as an array.

CSS is recognized automatically. To use another locator, change the selector text in the same rule, for example from "#email" to "role=textbox[name='Email']".

Read attributes with "output":"@attribute", such as "@href", "@id", or "@data-price". Relative URLs remain relative. CSS multi-valued attributes such as @class and @rel return arrays. The shorthand "a@href" is not supported.

Rule options​

FieldAccepted valueBehavior
selectorRaw locator stringRequired. Identifies elements to read; CSS is recognized automatically.
outputOutput name or nested rule objectDefaults to text. See Output formats.
typeitem or listDefaults to item, which reads the first match. list reads all current matches.
match_indexPositive integerSelects a specific match. Indexes start at 1.
filterObject with has_text and/or has_not_text string valuesNarrows matches by text within the element.

A worked example​

Suppose the page contains these orders:

<h1>Orders</h1>
<label for="email">Email</label>
<input id="email" value="alex@example.com" />
<article class="order">
<h2>Order A-100</h2>
<a href="/orders/A-100">View order</a>
<span class="status">Paid</span>
</article>
<article class="order">
<h2>Order A-101</h2>
<a href="/orders/A-101">View order</a>
<span class="status">Pending</span>
</article>

Each row below is a complete Data extraction rules input and the JSON returned in Extracted content:

Use it toExtraction rulesOutput
Read the page heading{"title":"h1"}{"title":"Orders"}
Read the current email{"email":{"selector":"role=textbox[name='Email']","output":"value"}}{"email":"alex@example.com"}
Read the first order URL{"url":{"selector":"a","output":"@href"}}{"url":"/orders/A-100"}
Read all order names{"names":{"selector":"h2","type":"list"}}{"names":["Order A-100","Order A-101"]}
Read fields from the first order{"order":{"selector":"article.order","output":{"name":"h2","status":".status"}}}{"order":{"name":"Order A-100","status":"Paid"}}

For the same page, these selectors return the following values when used as string rules:

SelectorResult
h1Orders
xpath=//h1Orders
role=heading[name="Orders"]Orders
text=/order a-100/iOrder A-100
css=article.order >> css=.statusPaid
article.order >> nth=1 >> css=.statusPending
Selector featureExampleHow it works
Accessibility rolerole=textbox[name='Email']Matches the role and accessible name; the input's Email label supplies its name.
Text patterntext=/order a-100/iMatches text without case sensitivity.
Selector chainarticle.order >> css=.statusSelects the status within an order.
Match index in a locatorh2 >> nth=1Selects the second match; nth starts at zero.
Placeholderinput[placeholder='Enter email']Matches the placeholder attribute.
Image alt textimg[alt='Company logo']Matches the image's alt attribute.
Title[title='Close']Matches the title attribute.
Test ID[data-testid='order-total']Matches a test ID attribute.

Enter locator text just as you would in another web action's Element identifier.

Advanced extraction​

Lists and nested objects​

Use type: "list" for every match and a nested output object for fields within each item. These examples use the orders page above:

Use it toExtraction rulesOutput
Read a field from each order{"orders":{"selector":"article.order","type":"list","output":{"name":"h2"}}}{"orders":[{"name":"Order A-100"},{"name":"Order A-101"}]}
Read the enclosing link's text and URL{"link":{"selector":"a","output":{"text":{"selector":"@"},"url":{"selector":"@","output":"@href"}}}}{"link":{"text":"View order","url":"/orders/A-100"}}

selector: "@" selects the enclosing matched item inside a nested output.

XPath formExampleScope and result
Top-level bare XPath{"urls":"//a/@href"}Reads matching element, text, or attribute nodes from the document and joins results with spaces.
Nested bare XPath"name":"//h2" inside a nested outputSearches the document of the selected element's frame, then reads the first match's leading text. It can return null when there is no leading text. Use an object rule with output: "text" for complete element text.
Explicit relative XPath{"selector":"xpath=.//a","output":"@href"} inside a nested outputReads a link relative to the enclosing matched item.
Explicit XPath locator{"title":"xpath=//h1"}Selects elements and reads the first match's text; text and attribute nodes are not locator targets.

Filter or select a specific match​

Filters narrow matches before match_index is applied. These examples use the headings from the orders page:

Use it toExtraction rulesOutput
Read the first match by default{"name":"h2"}{"name":"Order A-100"}
Read the second match with an option{"name":{"selector":"h2","match_index":2}}{"name":"Order A-101"}
Read the second match in a locator{"name":"h2 >> nth=1"}{"name":"Order A-101"}
Include and exclude text{"name":{"selector":"h2","filter":{"has_text":"A-100","has_not_text":"Cancelled"}}}{"name":"Order A-100"}
Read every match{"names":{"selector":"h2","type":"list"}}{"names":["Order A-100","Order A-101"]}

match_index starts at 1; nth starts at zero. Item rules default to the first match. List rules without an index read all current matches.

Output formats​

OutputReturned value
textLegacy text extraction, trimmed at the ends. It can include hidden text. Directly selected scripts, styles, and templates return their text.
@attributeHTML attribute value; missing attributes return an empty string.
htmlOuter HTML of the selected element, using the compatible HTML serialization format.
inner_htmlInner HTML of the selected element.
inner_textRendered text, such as the visible label inside a container.
text_contentDOM text content without the legacy trimming or whitespace normalization.
value or input_valueCurrent value of an input, textarea, or select.
checkedBoolean checkbox or radio state.
visibleBoolean visibility of a matched element.
enabledBoolean enabled state of a matched element.
countNumber of matches, including zero.
table_jsonTable or ARIA grid rows as an array of objects keyed by headers.
table_arrayTable or ARIA grid rows as an array of arrays, including the header row.

For an input initially set to alex@example.com, then edited to updated@example.com:

OutputReturned valueUse it to
value or input_valueupdated@example.comRead what the user entered.
@valuealex@example.comRead the original HTML attribute.
Other exampleExtraction rulesReturned value
Checkbox state{"accepted":{"selector":"#accept-terms","output":"checked"}}A boolean indicating whether the checkbox is checked.
JSON in a script{"json_ld":{"selector":"script[type='application/ld+json']","output":"text"}}A string containing the script's JSON.

Text and HTML output can contain hidden content. There is no clean option; choose text_content for DOM text without legacy normalization.

Tables and ARIA grids​

Table sourceHeadersRows
HTML tableFirst nonempty row.Remaining rows.
ARIA gridElements with the columnheader role.Elements with row and gridcell roles; common hidden helper text is excluded.

For a table selected by #orders, with headers Name and Status and one row containing Alex and Active:

Extraction rulesOutput
{"rows":{"selector":"#orders","output":"table_json"}}{"rows":[{"Name":"Alex","Status":"Active"}]}
{"rows":{"selector":"#orders","output":"table_array"}}{"rows":[["Name","Status"],["Alex","Active"]]}

Only rows loaded in the page are returned. Extraction does not scroll or paginate to load the rest of a virtualized grid.

Iframes and shadow DOM​

Keep iframe traversal in the locator string. The internal:control=enter-frame transition enters the matched iframe, then the rest of the locator selects within it:

{
"first_name": {
"selector": "iframe[title=\"Form 0\"] >> internal:control=enter-frame >> internal:role=textbox[name=\"First name*\"i]",
"output": "value"
}
}
SituationHow to handle it
Enter an iframeUse internal:control=enter-frame in the locator string; no separate frame input is needed.
Select by role inside the iframeUse internal:role; the i flag makes the accessible-name match case-insensitive.
Enter nested iframesRepeat the iframe selector and transition for each level.
Several iframes matchNarrow the iframe selector or add >> nth=0 before the frame transition. Each iframe step must identify one frame.
Choose a final target matchUse match_index; it applies to the target element and does not choose an intermediate iframe.
Iframe is missingThe action fails.
Iframe exists but the target is missingThe usual missing-value results apply.
Extract nested outputsRules run within the selected element's frame.
Select inside an open shadow rootCSS and other native locators can reach it; XPath cannot.
Select inside a closed shadow rootUnavailable.
Read a templateSelect the template itself to read its stored content; its descendants are not live locator targets.

Ordinary CSS does not cross iframe boundaries automatically.

Page readiness​

Page stateWhat to doExtraction behavior
Content is still loadingUse Check element or existing web automation steps to check readiness first.Reads the current matches.
A list or grid loads more rows on scrollLoad the rows you need before extracting.Returns loaded rows without scrolling, pagination, or waiting for a requested count.

Missing values and compatibility​

Rule or outputResult when missing
CSS or advanced locator stringnull
Top-level bare XPath string""
Nested bare XPath stringnull
Object rule with type: "item"{}
Object rule with type: "list"[]
output: "count"0
@attribute on an existing element""

With CSS/native locator strings or an object rule's text output, an existing element with empty text returns "". A top-level bare XPath string also returns "" when no nodes match, so that shorthand does not distinguish those cases. Nested bare XPath shorthand reads leading text and can return null when a matched element has no leading text; use an object rule for complete element text.

Existing CSS/XPath rule shapes, list and item behavior, text trimming, relative attribute URLs, and table formats remain supported. Browser normalization of malformed markup and parser-specific CSS/XPath expressions can still affect results.

AI extraction​

Choose AI Extraction, enter an optional Query, and provide a JSON Schema in AI data extraction rules. For example, use the query "Extract the first three products with their names and prices" with this schema:

{
"type": "object",
"properties": {
"products": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"price": {"type": "string"}
},
"required": ["name", "price"]
}
}
},
"required": ["products"]
}

The JSON Schema describes the result; it does not use selector, output, or the other selector-rule fields. Selector extraction rules do not apply to AI extraction.

Configure extraction in a Wrkflow​

  1. Open a browser session with Open web session, then navigate to the page containing the values.
  2. Add Retrieve value(s) and map the Browser session ID from that session.
  3. Choose Advanced selectors and enter a JSON object in Data extraction rules. For AI extraction, choose AI Extraction and provide its query and schema instead.
  4. Run the Wrk Action test and inspect Extracted content in Test Results.
  5. Create Custom Outputs for the values downstream actions need. For the examples above, $.email selects the email address and $.orders[*].name selects the order names from a nested list.
  6. Use those named values from the Data Library in the next Wrk Action.

Troubleshooting​

SymptomWhat to check
null, {}, or [] instead of the expected valueCheck the selector, the active page, the frame, and whether content has loaded.
Only one value is returnedUse type: "list" to read all matches.
Nested XPath repeats the same value in every itemUse an explicit relative XPath locator string, such as xpath=.//a.
A form value is outdatedUse value rather than @value.
Several iframes matchUse a more specific frame selector.
A table has fewer rows than expectedLoad or scroll to the remaining rows before extraction.