Touch-ΡΠΎΠ±ΡΡΠΈΡ
Please read the Terms of Use for Materials on ZennoLab
This page has been translated automatically
We want to provide you with the latest help content in your language as soon as possible. This page has been translated automatically and may contain grammatical errors or inaccuracies. We want this content to be useful to you. Please let us know at the bottom of this page if this information was helpful.
View the original article in Russian: Touch-ΡΠΎΠ±ΡΡΠΈΡ
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 has basic methods: TouchStart , TouchEnd , TouchMove , TouchCancel , as well as complex methods with Touch overloads, SwipeIntoView , SwipeBetween and others.
This is only the first stage of implementing touch events in the Chrome browser, so for now they are only available from C # code. In the next versions, control from the interface will be implemented.
Examples of
Emulation of touch-pressing
var tab = instance.ActiveTab;
var init = tab.FindElementByXPath("/html/body/button", 0); // ΠΡΠ΅ΠΌ HTML ΡΠ»Π΅ΠΌΠ΅Π½Ρ ΡΠ΅ΡΠ΅Π· XPath
tab.Touch.Touch(init); // ΠΠΌΡΠΌ ΠΏΠΎ Π½Π΅ΠΌΡ
Β
Scrolling
var tab = instance.ActiveTab;
HtmlElement init = tab.FindElementByXPath(".//button", 0); // ΠΡΠ΅ΠΌ HTML ΡΠ»Π΅ΠΌΠ΅Π½Ρ ΡΠ΅ΡΠ΅Π· XPath
tab.Touch.SwipeIntoView(init); // Π‘ΠΊΡΠΎΠ»Π»ΠΈΠΌ ΡΠΊΡΠ°Π½ ΡΠ°ΡΠ°ΠΌΠΈ Π΄ΠΎ Π½ΡΠΆΠ½ΠΎΠ³ΠΎ HTML ΡΠ»Π΅ΠΌΠ΅Π½ΡΠ°
Β
Swipe right
var tab = instance.ActiveTab;
// ΠΡΠ΄Π΅ΠΌ Π΄Π΅Π»Π°ΡΡ ΡΠ²Π°ΠΉΠΏ Π²Π½ΡΡΡΠΈ HTML ΡΠ»Π΅ΠΌΠ΅Π½ΡΠ°. Π‘ΠΎΡΡΠ°Π²ΠΈΠΌ XPath Π²ΡΡΠ°ΠΆΠ΅Π½ΠΈΠ΅.
var canvas = tab.FindElementByXPath(@"//*[@id=""canvas""]", 0);
// ΠΠΎΠ»ΡΡΠ°Π΅ΠΌ Π΅Π³ΠΎ ΡΠ°Π·ΠΌΠ΅ΡΡ: ΡΠΈΡΠΈΠ½Ρ ΠΈ Π²ΡΡΠΎΡΡ
var width = canvas.BoundingClientWidth;
var height = canvas.BoundingClientHeight;
// ΠΠΏΡΠ΅Π΄Π΅Π»ΡΠ΅ΠΌ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΡ ΠΏΠ΅ΡΠ²ΠΎΠ³ΠΎ ΠΊΠ°ΡΠ°Π½ΠΈΡ ΠΏΠΎ ΠΎΡΠΈ X, ΠΈ ΠΏΠΎΡΠ»Π΅Π΄Π½Π΅Π³ΠΎ - ΠΊΠΎΠ³Π΄Π° ΠΎΡΠΏΡΡΠΊΠ°Π΅ΠΌ ΠΏΠ°Π»Π΅Ρ
var offsetX = width / 4;
var minX = canvas.DisplacementInBrowser.X + offsetX;
var maxX = minX + width - 2*offsetX;
// ΠΠΏΡΠ΅Π΄Π΅Π»ΡΠ΅ΠΌ ΠΊΠΎΠΎΡΠ΄ΠΈΠ½Π°ΡΡ ΠΏΠ΅ΡΠ²ΠΎΠ³ΠΎ ΠΊΠ°ΡΠ°Π½ΠΈΡ ΠΏΠΎ ΠΎΡΠΈ Y, ΠΈ ΠΏΠΎΡΠ»Π΅Π΄Π½Π΅Π³ΠΎ - ΠΊΠΎΠ³Π΄Π° ΠΎΡΠΏΡΡΠΊΠ°Π΅ΠΌ ΠΏΠ°Π»Π΅Ρ
var offsetY = height / 4;
var minY = canvas.DisplacementInBrowser.Y + offsetY;
var maxY = minY;
// ΠΠ΅Π»Π°Π΅ΠΌ ΡΠ²Π°ΠΉΠΏ Π²ΠΏΡΠ°Π²ΠΎ
tab.Touch.SwipeBetween(minX, minY, maxX, maxY);
Settings
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.
Β
Demonstration project
Download
Β