# Automating Font Selection in Notepad

Let's consider how to automate font selection in Notepad using a robot.

![](https://sherparpa.ru/wp-content/uploads/2024/02/risunok-1-1.png)

Suppose we need the robot to select the required font in this window. The task is complicated by the presence of a scroll bar.

Click the Record Click Sequence button and record a click on any item from the long list of fonts. Click on BookmanOldStyle.

![](https://sherparpa.ru/wp-content/uploads/2024/02/risunok-2.png)

The block has been added to the current process. Let's examine the selector.

![](https://sherparpa.ru/wp-content/uploads/2024/02/risunok-3.png)

Note the last line. It contains the font name and its index number in the list — 38 (in the Index column). This means that on the computer where we intend to run the script, we must always have this font in the font list at number 38. If this condition is not met, the robot will not select this item. We can make it so that the robot selects the BookmanOldStyle font regardless of its number in the list, as the number may vary across different operating systems. Conversely, we could iterate through the list positions to select the font at a specific number regardless of its name. We can either remove the index number, in which case we will specifically search for BookmanOldStyle, or remove the font name and search by index. Here, as is often useful in iteration tasks, we can substitute variables into the selector cells. This can be done using the "Insert Variable" button.

Let's create Variable1 of text type.

![](https://sherparpa.ru/wp-content/uploads/2024/02/risunok-4.png)

Open the selector editor. You can insert the variable using the button or simply type its name manually into the cell.

![](https://sherparpa.ru/wp-content/uploads/2024/02/risunok-5.png)

Now the robot will search for the font stored in Variable1. Remember that the $ symbol must be placed before the variable name. The value in the Index column should be removed so that the search is independent of the font's position in the list.

If Variable1 is a number, then its value can be substituted into the Index column.

<figure><img src="https://sherparpa.ru/wp-content/uploads/2024/02/risunok-6.png" alt=""><figcaption></figcaption></figure>

Then we can create a loop where we iterate through all values of this variable, say from 1 to 100, and take the content of each element of this list into a text string to understand what fonts are available in the system. This can be done using the "Get Text" block.

How can we determine how many elements are in this list? To iterate through the entire list, we need to know the number of elements. This is not so critical, as we can predefine a large number of elements, for example, 3000, which will definitely never exist. We can then use the "If Error" connector to exit our loop.

Here's how it looks in practice:

There is a loop. Its initial value is 0 or 1. An important point: different applications and web pages may have different initial values for the element. It can be 0 or 1. You need to check in advance.

Let's set the initial value of our loop to 0 and the final value to 1000. For the loop iterator (the variable that will store a new value each time), we will use the Index variable.

![](https://sherparpa.ru/wp-content/uploads/2024/02/risunok-7.png)

Now we will connect the "Click Mouse" block to the loop's output, i.e., we will simply click through all these items. We will connect the output of the "Click Mouse" block to the start of the loop and place the next block – "Log".

![](https://sherparpa.ru/wp-content/uploads/2024/02/risunok-8.png)

If the mouse click is unsuccessful, i.e., we do not find the index of some item in this list, an error will occur. We will connect the "If Error" connector to the input of the next block after the loop (Log). We will write our Index variable in the selector.

![](https://sherparpa.ru/wp-content/uploads/2024/02/risunok-9.png)

Thus, we will be able to quickly go through and click on all items in this list, even if we do not know how many values there are. Referring back to the calculator example, we did this in one project where we needed to show mouse clicks on different buttons, select random numbers, add and subtract them, etc. Of course, we could have recorded 10 clicks on 10 buttons and then selected using 10 conditions (if the variable value = 1, then click this button, etc.). But we managed with just one click block, as inside this block in the selector, in the Index column, we wrote the Index variable containing the ordinal number.

![](https://sherparpa.ru/wp-content/uploads/2024/02/risunok-10.png)

Depending on what value is in this cell, the robot will click on that button.

The buttons for recording actions work quite similarly. For example, let's open Notepad and click the "Set Text to Element" button.

![](https://sherparpa.ru/wp-content/uploads/2024/02/risunok-11.png)

![](https://sherparpa.ru/wp-content/uploads/2024/02/risunok-12.png)

Let's set the text and save it.

![](https://sherparpa.ru/wp-content/uploads/2024/02/risunok-13.png)

The block is added to the current project.

![](https://sherparpa.ru/wp-content/uploads/2024/02/risunok-14.png)

It also has a selector; let's write "Hello" into it.

![](https://sherparpa.ru/wp-content/uploads/2024/02/risunok-15.png)

If you need to record this not as a constant but as a variable, then you need to write the name of the corresponding variable in this field.

![](https://sherparpa.ru/wp-content/uploads/2024/02/risunok-16.png)

The other click recording blocks work similarly.
