# Fine-Tuning Selector in Microsoft Word

Suppose you are working with a text editor. In the title bar of the text editor window, you will see not only its name (MS Word, etc.) but also the name of the current document after a hyphen. Let's say you do not want the robot to work only with this document in this scenario and not with any other.

Launch Word.

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

In the title bar of the text editor window, the name of the current document is displayed along with the name of the editor after a hyphen. Let's say the robot needs to find the Word editor window, but the document name is not important.

Try to record a click on some button in the Word window, for example, on the fill color button. Click the button to record the sequence of clicks.

![](https://sherparpa.ru/wp-content/uploads/2024/02/zapis-v-okne-word.png)

As an experiment, press the Ctrl key instead of clicking the left mouse button. That is, the action was recorded without actually clicking the button. Press escape to cancel and click the button ![](https://sherparpa.ru/wp-content/uploads/2023/11/image124-25w20h-5.png)(Save and Close).

A mouse click block has been added to the end of the current diagram:

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

Look at the selector of the block.

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

The first line searches for the application WINWORD. The second line searches for a window with the title Document1 – Word, i.e., it specifically searches for the document with the exact name Document1. This does not meet the task's requirements. It is necessary to ensure that the script works regardless of which document is open. The simplest thing to do is to delete the contents of this cell and save the selector table in this form.

Typically, the other conditions contained in this line are sufficient for the robot to find the desired control element. The line retains properties such as class name and control type.

Below are ways to check if the robot will work correctly in this case.

The first option: using the Check button at the top of the selector table.

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

The button performs a formal check for the presence of any element on the screen that matches the entire list of commands specified in the selector.

The second option: The Highlight button allows for a more interactive and visual demonstration of the robot's process of searching for a particular control element.

Click the Check button. The designer collapses, but the check ended unsuccessfully.

![](https://sherparpa.ru/wp-content/uploads/2024/02/proverka-neudachnoe-zavershenie.png)

When clicking the Highlight button, it is visible that the Word application window was identified, but then some error occurred. The error can be found in the log.

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

Clearly, the problem arose in the second line, in the ClassName cell with the value MsoDockTop. This element was not found. Theoretically, there should be no issues, but that is not the case.

Record the selector again without editing it. Click the button to record the sequence of clicks. Click the fill color button. Go to the designer and open the selector of the new block. Click the Check button. However, even in its original form, the script does not work. According to the log, the robot also stops at the second line.

![](https://sherparpa.ru/wp-content/uploads/2024/02/oshibka-robota-log.png)

Sometimes, when hovering the mouse cursor over a panel, something in the properties of that panel changes. The most common problem when launching selectors is that the class name of some button or link on the site changes. When the mouse cursor is over the element, the class name is one thing. When the mouse cursor leaves the element, the class name changes – that is how the page is structured. Most likely, this happened in this case when you recorded the click on the fill color button while hovering over it.

Let's consider if this is the problem and what actions need to be taken to debug the selector.

First, try loosening one of the conditions in the problematic line. Start by removing the value in the Index cell (2), then click the Check button. A window with the title Document1 – Word opens, i.e., everything works correctly. A green checkmark appears on the Check button in the selector table. The formal check of the selector has passed.

![](https://sherparpa.ru/wp-content/uploads/2024/02/formalnaya-proverka-selektora-projdena.png)

Click the Highlight button. After clicking this button, the robot will sequentially go through all the steps – the lines of the selector and will highlight the current step each time, i.e., the element on the screen that it is currently on.

![](https://sherparpa.ru/wp-content/uploads/2024/02/shag-raboty-selektora.png)

First, the robot found and highlighted the entire window, then found and highlighted the toolbar within the window, then found and highlighted the Paragraph section within the toolbar, and finally found and highlighted the fill color button within it.

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

Moreover, the robot found this button by its outer contour, as the button consists of two parts: the button itself and the arrow that calls the palette. In the last step, the robot highlighted the fill button itself.

Thus, you have repaired the selector.

Sometimes it is possible to simply delete the entire problematic line instead of guessing which of the conditions is unnecessary. This will work if there is no other instance of the next line within the top-level container on the screen. In this selector, the line after the problematic one fits this condition:

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

Try deleting the problematic line.

![](https://sherparpa.ru/wp-content/uploads/2024/02/udalenie-stroki-v-selekte.png)

Save the selector, re-enter it, and click the Check button.

The check has been successfully completed.

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

Return to the original example. It is necessary for the selector to be universal and work with any Word documents, not just Document1.

Delete the contents of this cell in the selector and check the selector's operation.

![](https://sherparpa.ru/wp-content/uploads/2024/02/udalenie-soderzhimogo-yachejki.png)

The selector works.

There is another way – there is functionality for inserting wildcards. You can insert a question mark, which will replace any single character, or an asterisk, which will replace multiple characters.

![](https://sherparpa.ru/wp-content/uploads/2024/02/vstavka-znaka-voprosa.png)

That is, you can write the value of the Name cell in the second line as “\* - Word”

![](https://sherparpa.ru/wp-content/uploads/2024/02/znachenie-v-yachejke.png)

This technique can be useful if you need to clarify to the robot which of the many similar elements we are dealing with.

If you are not satisfied with the result, you can rewrite the selector using the Record button in the selector table.

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

You can also manually add a new line using the “Add New Line” button and automatically specify some parameters in the selector line.

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