Find Element
Finds a single HTML element that matches a CSS selector and returns its outer HTML.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
info
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- HTML - The HTML content to search within.
- CSS Selector - The CSS selector pattern to match an element.
Options
- Contains Filter - Optional text that the matched element must contain.
- Exclude Filter - Optional text that the matched element must not contain.
Output
- HTML Element - A string containing the outer HTML of the matched element.
How It Works
The Find Element node searches HTML content using a CSS selector and returns the outer HTML of a single matching element. When executed, the node:
- Retrieves the HTML and CSS Selector input variables
- Validates that both HTML and CSS Selector are not empty
- Parses the HTML content into a goquery document
- Applies optional filtering:
- Contains Filter - Only includes elements that contain the specified text
- Exclude Filter - Excludes elements that contain the specified text
- Finds elements that match the CSS selector
- Validates that exactly one element matches (returns an error if zero or multiple elements match)
- Extracts the outer HTML of the matched element
- Sets the outer HTML string as the output variable
Requirements
- Valid HTML content to search within
- Valid CSS selector pattern that matches exactly one element
- Non-empty HTML and CSS Selector inputs
Error Handling
The node will return specific errors in the following cases:
- Empty or invalid HTML input - "HTML input can not be empty"
- Empty or invalid CSS Selector input - "CSS Selector input can not be empty"
- Malformed HTML that cannot be parsed - "Html data parse error"
- No elements found matching the CSS selector - "Element not found."
- Multiple elements found matching the CSS selector - "The CSS selector matches ambiguous multiple elements, but only one is expected."
Usage Notes
- Uses standard CSS selector syntax for element matching
- Supports complex selectors like
.class
,#id
,tag.class
,tag[attr=value]
, etc. - The Contains Filter and Exclude Filter options work on the text content of elements
- Returns the outer HTML of the matched element, preserving its complete structure
- Useful for web scraping, content extraction, and HTML processing tasks
- The outer HTML includes the element's opening tag, content, and closing tag
- Can be chained with other DOM Parser nodes to further process the extracted element
- Designed to find exactly one element - use Find All Elements if you need to match multiple elements
- When no filters are applied, returns the first element matching the CSS selector