Previous topic

Check the Right Checkbox

Next topic

Desktop Surveillance

This Page

Working with SlidersΒΆ

In this tutorial, we will learn how to use dragDrop() and spatial operators by writing a number of scripts to manipulate sliders.

Suppose we wish to lower the speaking rate of the Text to Speech function. We want to drag the slider to the slow side in the Speech preferences window shown below.


The function that can perform the dragging is dragDrop(). This function takes two images as arguments. The first image describes the source GUI object to drag and the second image describes the appearance of the destination location where the GUI object should be dragged to and dropped.

Let us capture the source and destination images respectively.

1dragDrop(, )

What happen if there are more than two sliders. How can we make sure the right slider is dragged? The above example works because the particular window only has one slider. How can we deal with cases when there are several instances of similar looking GUI components? Let us consider the Sound preferences window shown below.


Suppose we wish to lower the Alert volume. To make sure Sikuli Script drags the right slider, we need a way to tell Sikuli Script to look for the one that is to the right of the Alert volume label, not the one next to the Output volume label. Sikuli Script provides a set of spatial operators to do exactly this. Here we will apply the right() operator as follows.

1t = find().right().find()

This statement tells Sikuli Script to first find the Alert volume label and then find the slider thumb only within the region strictly to the right of the result of the first find. The slider thumb found is then stored in the variable t. Now that we have identified the desired slider thumb, we can call dragDrop() to drag it to the left by giving the image of the Alter volume as the target.

1dragDrop(t, )

In the above example, we use the image of the Alert volume label to implicitly guide the direction of dragging to the left. It is also possible to use relative coordinates to explicitly drag to the left, as shown below.

1dragDrop(t, [t.x - 200, t.y])

Here, the (x,y) coordinates of the slider thumb are accessible as the attributes of t. We can thus calculate the position 200 pixels to the left of t and ask Sikuli Script to drag the thumb to that position.