Block reference / Web interaction
Attribute value
Read or set an HTML attribute on an element, such as a link's href or an image's src.
Only in
WarpX Browser
Use Attribute value to read something that is not visible text: a link's address, an image's source, a data- attribute, or whether a checkbox is ticked. It can also write an attribute, for example to change a link's target before clicking it. For the visible text of an element, use Get text instead.
Settings
- Element Selector
The element to act on, as a CSS selector or an XPath; anything starting with
/,(,@orid(is read as XPath, and it can hold a reference such as{{variables.selector}}. The crosshair button (Select an element) lets you pick the element in the profile's browser, including inside iframes and shadow roots, and the check button (Verify selector) tests what you typed.Example.product-card a.title- Multiple
Reads every matching element instead of only the first. The result is then a list with one value per element.
ExampleChecked- Mark elementwhen the selector is CSS
Tags every element the block acts on and skips tagged elements the next time this block runs, so inside a loop each run takes the next untouched match. Only offered for CSS selectors.
ExampleUnchecked- Wait for selector
Keeps looking for the element until it appears or Selector timeout (ms) runs out. Off, the element must already be on the page when the block runs, or the block fails.
ExampleChecked- Selector timeout (ms)when Wait for selector is on
How long Wait for selector keeps looking, in milliseconds. The default is
5000.Example8000- Action
Get attribute value reads the attribute; Set attribute value writes it on every matched element.
ExampleGet attribute value- Attribute name
The attribute to read or write, without quotes, for example
href,src,data-skuorchecked. Forhrefon a link you get the full address, and forcheckedon a checkbox or radio you gettrueorfalse.Examplehref- Attribute valuewhen Action is Set attribute value
The value to write. It can hold a reference such as
{{variables.target}}.Example_self- Assign to variablewhen Action is Get attribute value
Also stores the result in a workflow variable. With Multiple on, the variable holds the whole list.
ExampleChecked- Variable namewhen Action is Get attribute value, Assign to variable is on
The variable to write. Later blocks read it as
{{variables.productLinks}}; start the name with$push:to append to a list instead of replacing it.ExampleproductLinks- Insert to tablewhen Action is Get attribute value
Writes the result into the workflow's table. With Multiple on, each match becomes its own row, unless the column's type is array.
ExampleChecked- Select columnwhen Action is Get attribute value, Insert to table is on
The table column to write to. Later blocks read the first row as
{{table.url}}and the last as{{table.$last.url}}; if you pick none, the value goes into a column namedcolumn.Exampleurl- Add extra rowwhen Action is Get attribute value
Writes a second, fixed value into another column next to every row this block inserts. Use it to label rows, for example with the search term they came from.
ExampleChecked- Valuewhen Action is Get attribute value, Add extra row is on
The value written into the extra column. It can hold a reference such as
{{variables.keyword}}.Example{{variables.category}}- Select columnwhen Action is Get attribute value, Add extra row is on
The column that receives the extra value.
Examplecategory
Every block also has the shared block settings — a description, Disable block and what to do on an error, and Finding elements explains selectors in more depth. Fields that take text accept data from earlier blocks.
What it hands on
With Get attribute value, the value (or a list of values with Multiple on) goes to the chosen table column and, if ticked, to the variable. An attribute the element does not have reads as empty. Set attribute value writes nothing. The block leaves by its single output; if no element matches, it fails.
Example: Collect product links from a category page
- Start
- New tab
- Attribute value
- Add a New tab block and set its URL to the category page, for example
https://shop.example.com/c/headphones. - Add an Attribute value block and set Element Selector to
.product-card a.title. - Tick Multiple so every product on the page is read, and tick Wait for selector so the list has time to render.
- Leave Action on Get attribute value and set Attribute name to
href. - Tick Insert to table and pick the
urlcolumn. Each link becomes its own row. - Run the workflow and open the table: the
urlcolumn holds one full address per product.
Good to know
- If no element matches, the block fails with an element-not-found error and the workflow stops. To carry on instead, set On error in the block's settings to Continue flow or Execute fallback.
- The value is read from the page as it is now. For a text field's current contents,
valuereturns the attribute written in the HTML, not what has been typed since; read it with JavaScript code instead. - Set attribute value changes the element in the page only. It is gone when the page reloads.
See also
- Get text — Read the text of one element or many, and save it to the table or a variable.
- Loop elements — Run the blocks after it once for each element that matches a selector, loading more as it goes.
- Insert data — Set variables and add values to the workflow's table, several at once.