Touch Event

Touch Event

Table of contents


Description

This action allows you to emulate a Touch event (finger clicks).


How to add an action to a project?

Through the context menu Add ActionTabsTouch Event

Or use smart search .


Where can it be applied?

  • In cases where you need to emulate a phone or any other touchscreen device

  • In cases when you need to bring all actions as close as possible to human ones.


How to work with an action?

It is necessary to enable “Record” and “Touch” input mode in the browser window so that all actions executed in the browser are automatically recorded as Touch events.

Select an event

  • Touch - pressing (click / touch);

  • Long Touch - long clamping (right click)


Element search

Table of contents


Before you can interact with an element on the page, you need to find it. In the Get Value, Set Value, Rise Event, Touch Event, Swipe Event actions, there are two ways to find items - classic and using XPath.


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

 

 

 

 

XPath - Search using XPath expressions . With the help of it you can implement a more versatile and resistant to layout changes way of data search in comparison with classic search or regular expressions.

 

Which tab

Select the tab on which the item will be searched.
Possible values:

  • Active tab

  • First

  • By name - when you select this item, an input field for the name of the tab will appear.

  • By number - in the entry field you will need to enter the serial number of the tab (numbering starts from zero!)

Document

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

Form

It is also better to set -1 (search in all forms on the page). Choosing this value will make the template more versatile.

Example: on page 3 of the form - search, registration, ordering goods. We need to click on the button in the order form and we have chosen as the value of the “Form” field - 2 (numbering from zero). After some time, a new login form appears on the site, and it is inserted in front of the order form. Number 2 will now be the login form, and our template will either give an error that the button was not found, or (much worse) will click on another button in another form.

In the program settings, you can select two checkboxes - Search all forms on the page and Search all documents on page, and then always when adding an element to the Action Designer, the document number and form will be set to -1.

Tag (classic search only)

The actual HTML tag from which you want to get the value.

You can specify several tags at once, the separator is; (semicolon)

Conditions (classic search only)

  1. Group - the priority of this condition. The higher this number, the lower the priority. If we could not find an element by the condition with the highest priority, then go to the condition with the next priority, and so on until the element is found, or until the search conditions are over. You can add several conditions with the same priority, then the search will be performed for all conditions with the same priority at the same time. 

  2. Attribute - HTML attribute of the tag by which the search is performed.

  3. Search type :

    1. text - search by full or partial text occurrence;

    2. notext - search for elements that do not contain the specified text;

    3. regexp - search using regular expressions
      By default RegeXp search is case insensitive. To change it you can prepend (?-i) to your expression (this mean “disable case insensitive mode”).

  4. Value - the value of the HTML tag attribute

  5. Match # - the ordinal number of the found element (numbering from zero!). Ranges and variable macros can be used in this field.

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

Several conditions can be used to find the desired item.

It is always important to try to select search conditions in such a way that only one element remains, i.e. the serial number was 0 (numbering from zero).

 


Coordinates

Search for element by Coordinates.

Execute a Touch event within the specified coordinates.

  1. Which tab is Active /First / By name / By number

  2. Coordinates - you need to enter a range of X and Y coordinates. You can use project variables - {-Variable.example_var-} .


Usage example

Take as an example our resource where you can practice making simple clicks - https://lessons.zennolab.com/en/index . For implementation, we will use the Action Designer .

Go to the page in ProjectMaker'e.

We go down to the bottom and find the field for pressing and selecting the OS. Click on the place for the "checkmark" with the right mouse button and select "In the constructor of actions.

We select the action Rise , Event touch . Click on the Test button to check.

If the click was successful, then click Add to project


Examples of work in C#

Starting with version 7.1.4.0, a Touch property with a set of methods has been added to the CommandCenter.Tab. The Touch property contains basic methods: TouchStart, TouchEnd, TouchMove, TouchCancel, as well as complex methods with Touch overloads, SwipeIntoView, SwipeBetween and others.

Emulation of touch-pressing

var tab = instance.ActiveTab; var init = tab.FindElementByXPath("/html/body/button", 0); // Searching for an HTML element via XPath tab.Touch.Touch(init); // Click on it

Scrolling

var tab = instance.ActiveTab; HtmlElement init = tab.FindElementByXPath(".//button", 0); // Searching for an HTML element via XPath tab.Touch.SwipeIntoView(init); // Scroll the screen with touchscreens to the desired HTML element

Swipe right

var tab = instance.ActiveTab; // We will swipe inside the HTML element. Let's compose an XPath expression. var canvas = tab.FindElementByXPath(@"//*[@id=""canvas""]", 0); // We get its dimensions: width and height var width = canvas.BoundingClientWidth; var height = canvas.BoundingClientHeight; // Determine the coordinates of the first touch along the X axis, and the last when you release your finger var offsetX = width / 4; var minX = canvas.DisplacementInBrowser.X + offsetX; var maxX = minX + width - 2*offsetX; // Determine the coordinates of the first touch along the Y axis, and the last when you release your finger var offsetY = height / 4; var minY = canvas.DisplacementInBrowser.Y + offsetY; var maxY = minY; // Swipe to the right tab.Touch.SwipeBetween(minX, minY, maxX, maxY);

Settings

Only part of the settings is displayed here. You can find a complete list in the documentation.

By default, a number of parameters are taken into account and randomized: speed, acceleration, motion curve, and others. All movements will be as natural as possible out of the box, but if you need to make adjustments to the behavior of touch events, there is such a possibility too.

var tab = instance.ActiveTab; var parameters = tab.Touch.GetCopyOfTouchEmulationParameters(); //We get the current settings of the touch // Then we write "parameters." and after the point, the syntax editor will prompt the available fields of this object. //////////////////////// // Some examples //////////////////////// parameters.Acceleration = 1.2f; // Let's put the acceleration harder parameters.MinCurvature = 0; // Let the minimum curvature be a straight line parameters.MaxCurvature = 1; // And the maximum curvature is a very strong bend. // Bend a curve closer to the starting point parameters.MinCurvePeakShift = 0f; parameters.MaxCurvePeakShift = 0.2f; parameters.MinStep = 1; // Lower initial speed parameters.MaxStep = 60; // And the final one is higher parameters.RightThumbProbability = 0.7f; // In 70% of cases the right finger will be used, and in 30% the left finger will be used. tab.Touch.SetTouchEmulationParameters(parameters); // IMPORTANT: WE APPLY THE SETTINGS - OTHERWISE WILL NOT CHANGE ANYTHING // More settings here: https://help.zennolab.com/en/v7/zennoposter/7.1.4/webframe.html#topic951.html // instance.ActiveTab.Touch.SetTouchEmulationParameters(new TouchEmulationParameters()); // Setting default settings

 

Demonstration project


Useful links