Skip to main content

Getting a Value

🔗 Original page — Source of this material


Description

This action is used to retrieve the value of a specified element. This can be:

  • Height/width
  • Inner text/HTML code
  • HTML attributes – id, class, name, style, and others
  • Tag name
  • And much more

How do I add the action to a project?

Via the context menu Add actionTabsGet value

image-20200808-162057

Or by using the ❗→ action builder.

Or you can use the ❗→ smart search.

How do I select an element to get a value from?

Let's look at an example: https://lessons.zennolab.com/ru/registration. Let’s say you need to extract the text of the button that submits the form. To do this, right-click on the button and select To Action Builder from the context menu.

image-20200808-163447

At the bottom, under the browser window, the ❗→ Action Builder will open.

image-20200811-071742

The data for the search will be automatically selected so that only one element is found as a result. Here’s what you should do:

  • In the Action field, choose Get^(1)^.
  • The button text is stored in the value attribute, so select it from the Attribute^(2)^ dropdown. In the Value field, the contents of the selected attribute will appear— in our example, it’s the text “Создать аккаунт” (“Create Account”).
  • Before adding the action to your project, it’s a good idea to test it by clicking the appropriate button (especially if you have made changes in the action builder).
  • (Optional but recommended) Add a comment to the action (especially for Get Value actions, since the default comment provides very little information).
  • Add the action to your project by clicking Add to project.

What is this used for?

  • Data parsing (though there is a more suitable tool for that – the ❗→ Parse Page action)

  • Checking for the presence of an element on the page. This can be useful to:

  • determine if you are logged in (for example, when you are logged in, a personal account button appears on the site— if it’s there, you’re good. Or vice versa: when logged in, some element disappears—like a “Login” button, and if it’s gone, you know you are logged in)

  • search for error messages (especially helpful when solving captchas: if the captcha is not solved correctly, a new HTML element with the error text often appears on the page; if a page like that appears after submitting a captcha, you need to try solving it again. Also, there is a special ❗→ Check for text action you can use to check for text on a page)

  • Checking element visibility: sometimes a template finds an element, but it isn’t actually visible on the page (due to HTML construction quirks), for example a registration button. To make sure it is really displayed, you can get its height and width attributes and check that each is greater than 0.

Action settings: "Main" tab

Once you’ve added the action through the ❗→ action builder, open its settings:

image-20210525-114330

What to grab

image-20210525-114646

Choose exactly what you want to get—id, class, innerText, innerHtml, value, height, width, style, etc.

You can also enter a value manually instead of selecting from the list. On websites, you’ll often see attributes like data-... (for example, data-name, data-value, data-testid, data-whatever). Such attributes (those not in the dropdown) can be entered manually.

Note

You can use project variables ({ -Variable.var_name- })

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

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

image-20200805-202115

XPath – search using ❗→ XPath expressions. This allows you to implement a more flexible and robust way of searching for data, compared to classic search or regular expressions.

image-20200805-202209

Which tab

Select the tab where the element search will be performed. Possible values:

  • Current tab
  • First
  • By name – when you choose this option, an input field to enter the tab name appears.
  • By number – you will need to enter the tab’s index (counting starts from zero!)

Document

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

Form

It’s also best to set -1 (search through all forms on the page). This makes your template more generic.

Why is it better to set "-1"?

Example: the page has three forms—search, registration, order. You want to click the order form’s button and set the “Form” value to 2 (numbering starts from zero). Later, a new form (login) is added before the order form. Now, index 2 points to the login form, and your template either fails to find the button (error), or worse—it clicks a button in the wrong form.

Note

There are two checkboxes in the program settings—Search in all forms on the page and Search in all documents on the page. When these are checked, -1 will be set automatically for document and form numbers when adding elements in Action Builder.

Tag (classic search only)

image-20210525-095347

The actual HTML tag whose value you need to get.

Tip

You can specify multiple tags, separated by a semicolon (;)

Conditions (classic search only)

image-20210525-100053

  1. Group – priority of this condition. The higher this number, the lower the priority. If the element couldn’t be found with the highest priority condition, the process goes to the next, and so on until the element is found or all conditions are exhausted. You can add several conditions with the same priority, in which case the search will be performed for all same-priority conditions at once.

  2. Attribute – the HTML tag attribute used for search.

  3. Search type:

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

  5. notext – search for elements where the specified text does not appear;

  6. regexp – search with ❗→ regular expressions By default, search is case-insensitive. To make your regular expression search case-sensitive, add (?-i) at the very beginning of the expression (this disables case-insensitive search)

  7. Value – the value of the HTML tag’s attribute

  8. # of match – the index of the found element (numbering starts from zero!). In this field, you can use ❗→ ranges and ❗→ variable macros.

Note

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

Note

To find the desired element, you can use multiple conditions.

It’s always important to try and set your conditions so that only one element is found, i.e., the index is 0 (numbering starts from zero).


Action settings: "Advanced" tab

image-20210525-114905

Wait before execution

How long the action will wait before execution.

Wait for element (timeout)

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


Example use case

Let’s look at one way to use this. Example: https://lessons.zennolab.com/ru/advanced.

We use ❗→ Set Value and ❗→ profile variables to fill the form fields. In a real project you might have to ❗→ recognize the captcha using services or ❗→ do it manually, but on this page the captcha image is always the same. After entering all the data, use the ❗→ Trigger event action to click the Create account button. From here, things can go in several directions:

If you filled everything correctly and solved the captcha, you get a page with the text Wellcome!

image-20200808-200553

If the captcha is wrong, you’ll see a page with wrong captcha

image-20200808-200620

Use the action builder to create a Get Value action that saves the text shown in the screenshots above. However, the variable ends up with a lot of extra stuff—like adv_reg, menu item names, etc. With ❗→ Text processing and a simple ❗→ regular expression (Wellcome!|wrong\ captcha) you search for either Welcome or wrong captcha. Using ❗→ Switch, you check what’s in your variable. If it’s Welcome, ❗→ send an informational message to the ❗→ log; if it’s wrong captcha—send a log message that registration failed.