/
Touch-события

Touch-события

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

Β