UiBot : Robots for Everyone!

Your Location: Training Center> Documents > 20.Image Command
20.Image Command

In addition to the usual "mouse" and "keyboard" classes, UiBot's "image" class commands are also very powerful. In the Command Area of the UiBot Creator, go to “Find Image,” and click “Expand” to see several commands which are shown in the following figure:

[insert figure]

The "Image" class command listed in the [UiBot Creator] 51 (imgsTarget/3.png){width="30%"}

Let's start with the Find Image command which does the following:

• Specify an image file in .bmp, .png, .jpg, etc. (the recommendation is to use .png format since it is lossless compression)

• Scan the specified area on the screen from left to right and top to bottom to see if the image appears in the specified area. If it does, the coordinates can be saved as a variable otherwise an exception will occur.

It seems complicated, but all you have to do is specify the image file and the area to scan, thus making the operation very simple. For example, we'll simulate clicking on the login button for WeChat Windows.

Suppose we have started WeChat and opened the login screen. Next, you we need to edit a process block in the UiBot Creator and insert a Find Image command by double-clicking or dragging. Then click on the "Find the Target" button (left below), similar to the one with the target command, and the UiBot Creator temporarily will hide the icon, turning it into an arrow and a picture (right). At this point, press the left button and drag it down to the right until a blue box is drawn. The blue box already contains the image you are looking for so release the left mouse button, and it's done! 52 ! [Use the Find Image command and specify image and lookup scope] (imgsTarget/4.png){width="90%"}

It seems like the above operation only drew a blue box, but the UiBot Creator actually has done more for us:

1. It has determined which window the blue box contains and can now record the characteristics of this window. In the future, you will need to find the window first and look for the diagram within the scope of the window.

2. It has saved the screen shot of the blue box automatically as a .png file into the res subdirectory of the directory in which the process is currently written. This is the picture to look for.

With the mouse click on the Find Image command, highlight it and the Property Bar on the right will display the properties of the command as shown in the following figure:

Attribute of the Find Image command (imgsTarget/5.png){width="30%"} 53 Two of the most important properties of a red box are the two that UiBot Creator does for us that I mentioned earlier. Within each of the other properties, "similarity" is a number between 0 and 1 which you can include to [blank] decimal places. The closer this number is to 1, the more stringent UiBot requires that each point must match. For example, a 0.9 allows for a small number of mismatches as long as the general match is in place. The meaning of the Cursor Position Property is that when an image is found, because the image is a rectangle, and the command output is just the coordinates of a point, which point in the rectangle is to be returned.The Activate Window property indicates whether the window you are looking for needs to be displayed in the foreground before looking at the diagram. If the window is obscured, then it can't be found properly even if there is an image on the window that we're looking for so this property is usually set to “Yes.”

Other properties that do not need to be changed will keep the default value. In the “Output to Property”, a variable name objPoint has been specified, and if the image is found successfully, the result is saved in this variable. This is illustrated below:

!! [View results width Output Debug Information] (imgsTarget/6.png){width="80%"}

Assuming that the image you are looking for is actually visible on the screen, you get the following results after running it:

The exact value may vary from computer to computer, but the principle remains unchanged. This value is a "dictionary" data type, and when the value is stored in the variable objPoint, you only need to write the values x and y in ````objPoint[x]' ``and ``objPoint[`y]'.

Once you get the center of the image, click this position with the mouse and simulate the logon operation of WeChat. You can do this by selecting the Simulate Move and Simulate Click commands contained in the Mouse class

The most critical property of the Simulate Move command is the manipulation of the screen position as shown in the figure below. Enter the results of the search image ``objPoint["x"]`````and ``objPoint["y"]``, respectively. Once the move is complete, do another "mock click" and left click at the center of the login button. At this point, we've simulated the full operation of clicking the Login button.

!! [View results width Output Debug Information] 55 (imgsTarget/7.png){width="80%"}

The three commands above are easy to understand and even users who have never learned UiBot can get a rough idea of what it means. However, to click a login button, three more commands are needed to complete it, and this is obviously too much. Take another look at all the commands under the "image" class provided by UiBot. The first of which is called "click image.” It's actually a combination of three commands: Find Image, Simulate Move, and Simulate Click. First, simply insert a Click Image command and press the Find Target button on the command. Next, drag the mouse to select the appropriate window and the image you’re looking for. After that, you can quickly complete the function of clicking the Login button on WeChat. Although it is a targetless command, it is isn’t more complicated than operating a command with a target.

With that in mind, you should be able to go back and forth between commands for several other image classes, including "move the mouse over the image", "judge whether the image exists," etc.

Are You Ready to Explore the RPA World?