【发布时间】:2020-06-05 14:33:14
【问题描述】:
puppeteer-sharp API 中的触摸屏只提供了一种方法:TapAsync。但我需要拖动(touchStart 和 touchEnd 和 touch move)。我该怎么做?
【问题讨论】:
标签: c# puppeteer puppeteer-sharp
puppeteer-sharp API 中的触摸屏只提供了一种方法:TapAsync。但我需要拖动(touchStart 和 touchEnd 和 touch move)。我该怎么做?
【问题讨论】:
标签: c# puppeteer puppeteer-sharp
PuppeteerSharp 没有这些 API(因为 Puppppeteer 没有这些 API)。但是,您可以尝试以与 TapAsync 相同的方式将这些消息发送到浏览器。
这是TapAsync 代码:
// Touches appear to be lost during the first frame after navigation.
// This waits a frame before sending the tap.
// @see https://crbug.com/613219
await _client.SendAsync("Runtime.evaluate", new RuntimeEvaluateRequest
{
Expression = "new Promise(x => requestAnimationFrame(() => requestAnimationFrame(x)))",
AwaitPromise = true
}).ConfigureAwait(false);
var touchPoints = new[] { new TouchPoint { X = Math.Round(x), Y = Math.Round(y) } };
await _client.SendAsync("Input.dispatchTouchEvent", new InputDispatchTouchEventRequest
{
Type = "touchStart",
TouchPoints = touchPoints,
Modifiers = _keyboard.Modifiers
}).ConfigureAwait(false);
await _client.SendAsync("Input.dispatchTouchEvent", new InputDispatchTouchEventRequest
{
Type = "touchEnd",
TouchPoints = Array.Empty<TouchPoint>(),
Modifiers = _keyboard.Modifiers
}).ConfigureAwait(false);
页面有一个公共属性Client。您可以使用该客户端来执行这些调用。
您可以查看here,类型支持:touchStart、touchEnd、touchMove 和 touchCancel。
【讨论】: