Skip to main content

Setting a Value

🔗 Original page — Source of this material


Description

The "Set Value" action is used to set values for various HTML elements:

  • Single-line input fields. HTML tag <input />. Commonly used to set names, passwords, addresses, and other values. Example
  • Multi-line fields. HTML tag <textarea />. Used when you need to enter a message, article text, or any other large amount of text.
  • Drop-down lists. HTML tag <select />. These can be found when selecting gender, country, and/or city in various registration forms.

Example of a form with the above fields:

Additionally, with this action, you can change not only visible text, but also the code of elements on the page. This can be useful when one element covers another; in such cases, it's enough to replace the extra element’s code with an empty string and it will be removed from the page.

How to add the action to a project?

Via the context menu Add ActionTabsSet Value

image-20200809-091229

Via ❗→ Action Builder.

Or use ❗→ Smart Search.

How to select a field to set a value?

Open the required page in the ProjectMaker browser and right-click the element you want to set a value for. From the context menu, select “❗→ To Action Builder”; the Action Builder will load below the browser window, select the action type “Set” and click the “Add to Project” button.

Action settings: “Main” tab

image-20210525-101913

What

image-20210525-102005

The text you want to insert. You can use plain text or macros like { -Variable.someVar- }, { -Profile.Name- }.

Where

image-20210525-102220

Here you need to choose the attribute of the element whose value you want to change:

  • value — the value of the element,
  • innerHtml\outerHtml (what's the difference) — the HTML code of the element (by setting one of these attributes to an empty value, you can remove the element from the page).
  • You can also specify more common HTML tags here — id, name, class, style, `placeholder```json .

This is not a complete list of possible values — there are others, but these are the most commonly used.

Tip

In this field you can enter a value manually, not just select from the options. You can also use project variables ({ -Variable.var_name- }) here.

Finding the Element

Before interacting with an element on the page, you first need to find it. In the actions ❗→ Get Value , ❗→ Set Value , ❗→ Execute Event , ❗→ Touch Event , ❗→ Swipe Event there are two ways to find elements — classic and via XPath.

Classic — Search by HTML element parameters: tag, attribute, and its value.

image-20200805-202115

XPath — Search using ❗→ XPath expressions. With XPath you can implement a more universal and layout-change-resistant way of searching for data compared to the classic search or regular expressions.

image-20200805-202209

Which Tab

Choose the browser tab where the element should be searched for. Possible values:

  • Active tab
  • First
  • By name — when selecting this option, a field will appear to enter the tab name.
  • By number — you’ll need to enter the tab's index (numbering starts from zero!)

Document

It is recommended to set this to -1 (search in all documents on the page). 

Form

Also, it's best to set -1 (search in all forms on the page). Choosing this value makes your template more universal.

Why is it better to set "-1"?

Example: There are 3 forms on the page — search, registration, product order. You need to click a button in the order form and select value 2 (numbering starts from zero) in the “Form” field. Later, a new form (login) appears on the site and is inserted before the order form. Now, form 2 is the login form, and your template will either throw a “button not found” error or (which is worse) click a button in the wrong form.

Tip

In the program’s settings, you can check two boxes — Search in all forms on the page and Search in all documents on the page. Then, whenever you add an element to the Action Builder, the document and form number will be set to -1 by default.

Tag (classic search only)

image-20210525-095347

The HTML tag whose value you want to get.

Advice

You can enter several tags at once, separated by ; (semicolon)

Conditions (classic search only)

image-20210525-100053

  1. Group — the priority of this condition. The higher the number, the lower the priority. If an element couldn't be found by the highest-priority condition, it moves to the next one, and so on until the element is found or all conditions are exhausted. You can add multiple conditions with the same priority — in this case, the search will be performed by all conditions of that priority at once.

  2. Attribute — the HTML tag attribute to search by.

  3. Search type:

  4. text — search by full or partial text match;

  5. notext — search for elements that do not contain the specified text;

  6. regexp — search using ❗→ regular expressions By default, the search is case-insensitive. To make it case-sensitive with regular expressions, add this at the start: ```(?-i)`(this disables case-insensitive search)

  7. Value — the value of the HTML tag attribute

  8. Match # — the index of the found element (numbering starts at zero!). You can ❗→ use ranges and ❗→ variable macros in this field.

Tip

To delete a search condition, left-click the field to the left of it (marked blue in the screenshot) and press the delete key on your keyboard.

Tip

Several conditions can be used for element search.

It is always important to select search conditions so that only one element remains, i.e., the index is 0 (numbering starts at zero).

Action settings: “Advanced” tab

image-20200805-204301

Wait

1. Wait before execution

How long the template will wait before setting the value.

2. Wait for element no more than

If the element does not appear on the page within the specified time, the action will end with an error.

3. Emulation

Default — uses the value from ❗→ project settings. Custom — you can set your own emulation level for this action (the project settings will be ignored in this case).


Example usage

Let's look at this action in a real-world example. We’ll use https://lessons.zennolab.com/ru/registration as a test site. On this page, you’ll see a simple form with three input fields and a button; for this article, we’re interested in the text input fields

image-20200805-205750

The easiest way to create this action is to right-click the input field and select “To Action Builder” from the context menu. Under the ProjectMaker browser, an ❗→ Action Builder will appear (if it wasn’t already open).

constructor

ProjectMaker tries to make your life as easy as possible, so the Action Builder will already have suggested search values^(1)^ (these fields are described above). Sometimes the program does not select the optimal values, and you’ll need to do that manually.

After you’ve chosen the element search parameters, click Search — below this button, there’s a field^(2)^ that will show as many elements as were found based on the specified settings (in our case, only one was found, so you see “0” in the field. As mentioned above — always try to set search parameters so that only one element is found). Here’s how this field looks when several elements are found:

multipleProjectMaker_kT4dWQIuxD

Next, select which attribute^(3)^ you want to update in the found element. In our case, value is selected, meaning the field’s displayed value will be changed. Then, enter the desired text in the Value field^(4)^. Here you can use ❗→ project variables in macro format: { -Profile.Name- }, { -Variable.generatedText- }, { -Page.Url- }. You can use variables to make complex strings, for example, a birth date string based on ❗→ profile values: { -Profile.BornDay- }.{ -Profile.BornMonth- }.{ -Profile.BornYear- }.

Then click the Test button^(5)^ and check if the value of the target element was updated. To make your project easier to read, you can add a comment^(7)^ to the action (an automatic comment is generated based on the entered Value, but it’s not always very useful).

Info

If you are developing a large and complex project that will need to be maintained over time, try to use Action comments as much as possible. A week, month, or even six months later, you’ll be able to understand how things work in your project by reading the comments, without needing to run it (to see what the action does) and/or digging into its settings. You can also use project notes.

caEo9nxYKK

After everything is set and confirmed, you can click Add to Project — your new action will appear on the project canvas.