How to use Touchscreen class of PuppeteerSharp.Input package

Best Puppeteer-sharp code snippet using PuppeteerSharp.Input.Touchscreen

Page.cs

Source:Page.cs Github

copy

Full Screen

...51 Client = client;52 Target = target;53 Keyboard = new Keyboard(client);54 Mouse = new Mouse(client, Keyboard);55 Touchscreen = new Touchscreen(client, Keyboard);56 Tracing = new Tracing(client);57 Coverage = new Coverage(client);58 _frameManager = new FrameManager(client, frameTree, this);59 _networkManager = new NetworkManager(client, _frameManager);60 _emulationManager = new EmulationManager(client);61 _pageBindings = new Dictionary<string, Delegate>();62 _logger = Client.Connection.LoggerFactory.CreateLogger<Page>();63 _ignoreHTTPSErrors = ignoreHTTPSErrors;64 _screenshotTaskQueue = screenshotTaskQueue;65 _frameManager.FrameAttached += (sender, e) => FrameAttached?.Invoke(this, e);66 _frameManager.FrameDetached += (sender, e) => FrameDetached?.Invoke(this, e);67 _frameManager.FrameNavigated += (sender, e) => FrameNavigated?.Invoke(this, e);68 _networkManager.Request += (sender, e) => Request?.Invoke(this, e);69 _networkManager.RequestFailed += (sender, e) => RequestFailed?.Invoke(this, e);70 _networkManager.Response += (sender, e) => Response?.Invoke(this, e);71 _networkManager.RequestFinished += (sender, e) => RequestFinished?.Invoke(this, e);72 Client.MessageReceived += client_MessageReceived;73 }74 internal CDPSession Client { get; }75 #region Public Properties76 /// <summary>77 /// Raised when the JavaScript <c>load</c> <see href="https://developer.mozilla.org/en-US/docs/Web/Events/load"/> event is dispatched.78 /// </summary>79 public event EventHandler<EventArgs> Load;80 /// <summary>81 /// Raised when the page crashes82 /// </summary>83 public event EventHandler<ErrorEventArgs> Error;84 /// <summary>85 /// Raised when the JavaScript code makes a call to <c>console.timeStamp</c>. For the list of metrics see <see cref="Page.MetricsAsync"/>.86 /// </summary>87 public event EventHandler<MetricEventArgs> Metrics;88 /// <summary>89 /// Raised when a JavaScript dialog appears, such as <c>alert</c>, <c>prompt</c>, <c>confirm</c> or <c>beforeunload</c>. Puppeteer can respond to the dialog via <see cref="Dialog"/>'s <see cref="Dialog.Accept(string)"/> or <see cref="Dialog.Dismiss"/> methods.90 /// </summary>91 public event EventHandler<DialogEventArgs> Dialog;92 /// <summary>93 /// Raised when JavaScript within the page calls one of console API methods, e.g. <c>console.log</c> or <c>console.dir</c>. Also emitted if the page throws an error or a warning.94 /// The arguments passed into <c>console.log</c> appear as arguments on the event handler.95 /// </summary>96 /// <example>97 /// An example of handling <see cref="Console"/> event:98 /// <code>99 /// <![CDATA[100 /// page.Console += (sender, e) => 101 /// {102 /// for (var i = 0; i < e.Message.Args.Count; ++i)103 /// {104 /// System.Console.WriteLine($"{i}: {e.Message.Args[i]}");105 /// }106 /// }107 /// ]]>108 /// </code>109 /// </example>110 public event EventHandler<ConsoleEventArgs> Console;111 /// <summary>112 /// Raised when a frame is attached.113 /// </summary>114 public event EventHandler<FrameEventArgs> FrameAttached;115 /// <summary>116 /// Raised when a frame is detached.117 /// </summary>118 public event EventHandler<FrameEventArgs> FrameDetached;119 /// <summary>120 /// Raised when a frame is navigated to a new url.121 /// </summary>122 public event EventHandler<FrameEventArgs> FrameNavigated;123 /// <summary>124 /// Raised when a <see cref="Response"/> is received.125 /// </summary>126 public event EventHandler<ResponseCreatedEventArgs> Response;127 /// <summary>128 /// Raised when a page issues a request. The <see cref="Request"/> object is read-only.129 /// In order to intercept and mutate requests, see <see cref="SetRequestInterceptionAsync(bool)"/>130 /// </summary>131 public event EventHandler<RequestEventArgs> Request;132 /// <summary>133 /// Raised when a request finishes successfully.134 /// </summary>135 public event EventHandler<RequestEventArgs> RequestFinished;136 /// <summary>137 /// Raised when a request fails, for example by timing out.138 /// </summary>139 public event EventHandler<RequestEventArgs> RequestFailed;140 /// <summary>141 /// Raised when an uncaught exception happens within the page.142 /// </summary>143 public event EventHandler<PageErrorEventArgs> PageError;144 /// <summary>145 /// This setting will change the default maximum navigation time of 30 seconds for the following methods:146 /// - <see cref="GoToAsync(string, NavigationOptions)"/>147 /// - <see cref="GoBackAsync(NavigationOptions)"/>148 /// - <see cref="GoForwardAsync(NavigationOptions)"/>149 /// - <see cref="ReloadAsync(NavigationOptions)"/>150 /// - <see cref="WaitForNavigationAsync(NavigationOptions)"/>151 /// </summary>152 public int DefaultNavigationTimeout { get; set; } = 30000;153 /// <summary>154 /// Gets page's main frame155 /// </summary>156 /// <remarks>157 /// Page is guaranteed to have a main frame which persists during navigations.158 /// </remarks>159 public Frame MainFrame => _frameManager.MainFrame;160 /// <summary>161 /// Gets all frames attached to the page.162 /// </summary>163 /// <value>An array of all frames attached to the page.</value>164 public Frame[] Frames => _frameManager.Frames.Values.ToArray();165 /// <summary>166 /// Shortcut for <c>page.MainFrame.Url</c>167 /// </summary>168 public string Url => MainFrame.Url;169 /// <summary>170 /// Gets that target this page was created from.171 /// </summary>172 public Target Target { get; }173 /// <summary>174 /// Gets this page's keyboard175 /// </summary>176 public Keyboard Keyboard { get; }177 /// <summary>178 /// Gets this page's touchscreen179 /// </summary>180 public Touchscreen Touchscreen { get; }181 /// <summary>182 /// Gets this page's coverage183 /// </summary>184 public Coverage Coverage { get; }185 /// <summary>186 /// Gets this page's tracing187 /// </summary>188 public Tracing Tracing { get; }189 /// <summary>190 /// Gets this page's mouse191 /// </summary>192 public Mouse Mouse { get; }193 /// <summary>194 /// Gets this page's viewport195 /// </summary>196 public ViewPortOptions Viewport { get; private set; }197 /// <summary>198 /// List of suported metrics provided by the <see cref="Metrics"/> event.199 /// </summary>200 public static readonly IEnumerable<string> SupportedMetrics = new List<string>201 {202 "Timestamp",203 "Documents",204 "Frames",205 "JSEventListeners",206 "Nodes",207 "LayoutCount",208 "RecalcStyleCount",209 "LayoutDuration",210 "RecalcStyleDuration",211 "ScriptDuration",212 "TaskDuration",213 "JSHeapUsedSize",214 "JSHeapTotalSize"215 };216 #endregion217 #region Public Methods218 /// <summary>219 /// Returns metrics220 /// </summary>221 /// <returns>Task which resolves into a list of metrics</returns>222 /// <remarks>223 /// All timestamps are in monotonic time: monotonically increasing time in seconds since an arbitrary point in the past.224 /// </remarks>225 public async Task<Dictionary<string, decimal>> MetricsAsync()226 {227 var response = await Client.SendAsync<PerformanceGetMetricsResponse>("Performance.getMetrics");228 return BuildMetricsObject(response.Metrics);229 }230 /// <summary>231 /// Fetches an element with <paramref name="selector"/>, scrolls it into view if needed, and then uses <see cref="Touchscreen"/> to tap in the center of the element.232 /// </summary>233 /// <param name="selector">A selector to search for element to tap. If there are multiple elements satisfying the selector, the first will be clicked.</param>234 /// <exception cref="SelectorException">If there's no element matching <paramref name="selector"/></exception>235 /// <returns>Task which resolves when the element matching <paramref name="selector"/> is successfully tapped</returns>236 public async Task TapAsync(string selector)237 {238 var handle = await QuerySelectorAsync(selector);239 if (handle == null)240 {241 throw new SelectorException($"No node found for selector: {selector}", selector);242 }243 await handle.TapAsync();244 await handle.DisposeAsync();245 }...

Full Screen

Full Screen

ElementHandle.cs

Source:ElementHandle.cs Github

copy

Full Screen

...244 }245 }246 }247 /// <summary>248 /// Scrolls element into view if needed, and then uses <see cref="Touchscreen.TapAsync(decimal, decimal)"/> to tap in the center of the element.249 /// </summary>250 /// <exception cref="PuppeteerException">if the element is detached from DOM</exception>251 /// <returns>Task which resolves when the element is successfully tapped</returns>252 public async Task TapAsync()253 {254 await ScrollIntoViewIfNeededAsync().ConfigureAwait(false);255 var (x, y) = await ClickablePointAsync().ConfigureAwait(false);256 await Page.Touchscreen.TapAsync(x, y).ConfigureAwait(false);257 }258 /// <summary>259 /// Calls <c>focus</c> <see href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus"/> on the element.260 /// </summary>261 /// <returns>Task</returns>262 public Task FocusAsync() => EvaluateFunctionAsync("element => element.focus()");263 /// <summary>264 /// Focuses the element, and sends a <c>keydown</c>, <c>keypress</c>/<c>input</c>, and <c>keyup</c> event for each character in the text.265 /// </summary>266 /// <param name="text">A text to type into a focused element</param>267 /// <param name="options">type options</param>268 /// <remarks>269 /// To press a special key, like <c>Control</c> or <c>ArrowDown</c> use <see cref="ElementHandle.PressAsync(string, PressOptions)"/>270 /// </remarks>...

Full Screen

Full Screen

Index.cshtml.cs

Source:Index.cshtml.cs Github

copy

Full Screen

...77 var left = rect.X + 10;78 var top = rect.Y + 10;79 var mouse = page.Mouse;80 await mouse.MoveAsync(left, top);81 await page.Touchscreen.TapAsync(left, top);82 await mouse.DownAsync();83 var startTime = DateTime.Now;84 await mouse.MoveAsync(left + 800, top, new PuppeteerSharp.Input.MoveOptions { Steps = 30 });85 await page.Touchscreen.TapAsync(left + 800, top);86 Console.WriteLine(DateTime.Now - startTime);87 await mouse.UpAsync();88 var success = await page.WaitForSelectorAsync(".yes", new WaitForSelectorOptions { Timeout = 3000 });89 string content = await page.GetContentAsync();90 91 var parser = new HtmlParser();92 var document = await parser.ParseDocumentAsync(content);93 aliToken = (document.GetElementById("aliToken") as IHtmlInputElement).GetAttribute("sms");94 aliSessionId = (document.GetElementById("aliSessionId") as IHtmlInputElement).GetAttribute("sms");95 aliSig = (document.GetElementById("aliSig") as IHtmlInputElement).GetAttribute("sms");96 }97 var response = await "https://upay.10010.com/npfwap/NpfMob/needdubbo/needDubboCheck?phoneNo=13113075869&amountMoney=200&channelKey=wxgz"98 .WithHeaders(new { Referer = "https://upay.10010.com/jf_wxgz" })99 .WithCookies(cookies)...

Full Screen

Full Screen

pay.cshtml.cs

Source:pay.cshtml.cs Github

copy

Full Screen

...53 var left = rect.X + 10;54 var top = rect.Y + 10;55 var mouse = page.Mouse;56 await mouse.MoveAsync(left, top);57 await page.Touchscreen.TapAsync(left, top);58 await mouse.DownAsync();59 var startTime = DateTime.Now;60 await mouse.MoveAsync(left + 800, top, new PuppeteerSharp.Input.MoveOptions { Steps = 30 });61 await page.Touchscreen.TapAsync(left + 800, top);62 Console.WriteLine(DateTime.Now - startTime);63 await mouse.UpAsync();64 }65 var channel = await page.WaitForSelectorAsync("[channelcode='alipaywap']");66 await channel.ClickAsync();67 var submit = await page.WaitForSelectorAsync("body > div.mask.confirmPay > section > div.btnPd > button");68 await submit.ClickAsync();69 }70 }71}...

Full Screen

Full Screen

Touchscreen.cs

Source:Touchscreen.cs Github

copy

Full Screen

...5{6 /// <summary>7 /// Provides methods to interact with the touch screen8 /// </summary>9 public class Touchscreen10 {11 private readonly CDPSession _client;12 private readonly Keyboard _keyboard;13 /// <summary>14 /// Initializes a new instance of the <see cref="Touchscreen"/> class.15 /// </summary>16 /// <param name="client">The client</param>17 /// <param name="keyboard">The keyboard</param>18 public Touchscreen(CDPSession client, Keyboard keyboard)19 {20 _client = client;21 _keyboard = keyboard;22 }23 /// <summary>24 /// Dispatches a <c>touchstart</c> and <c>touchend</c> event.25 /// </summary>26 /// <param name="x"></param>27 /// <param name="y"></param>28 /// <returns>Task</returns>29 /// <seealso cref="Page.TapAsync(string)"/>30 public async Task TapAsync(decimal x, decimal y)31 {32 // Touches appear to be lost during the first frame after navigation....

Full Screen

Full Screen

TouchScreenTests.cs

Source:TouchScreenTests.cs Github

copy

Full Screen

...12 private readonly DeviceDescriptor _iPhone = Puppeteer.Devices[DeviceDescriptorName.IPhone6];13 public TouchScreenTests(ITestOutputHelper output) : base(output)14 {15 }16 [PuppeteerTest("touchscreen.spec.ts", "Touchscreen", "should tap the button")]17 [SkipBrowserFact(skipFirefox: true)]18 public async Task ShouldTapTheButton()19 {20 await Page.EmulateAsync(_iPhone);21 await Page.GoToAsync(TestConstants.ServerUrl + "/input/button.html");22 await Page.TapAsync("button");23 Assert.Equal("Clicked", await Page.EvaluateExpressionAsync<string>("result"));24 }25 [PuppeteerTest("touchscreen.spec.ts", "Touchscreen", "should report touches")]26 [SkipBrowserFact(skipFirefox: true)]27 public async Task ShouldReportTouches()28 {29 await Page.EmulateAsync(_iPhone);30 await Page.GoToAsync(TestConstants.ServerUrl + "/input/touches.html");31 var button = await Page.QuerySelectorAsync("button");32 await button.TapAsync();33 Assert.Equal(new string[] {34 "Touchstart: 0",35 "Touchend: 0"36 }, await Page.EvaluateExpressionAsync<string[]>("getResult()"));37 }38 }39}...

Full Screen

Full Screen

Touchscreen

Using AI Code Generation

copy

Full Screen

1using PuppeteerSharp.Input;2using System;3using System.Threading.Tasks;4{5 {6 static async Task Main(string[] args)7 {8 {9 };10 using (var browser = await Puppeteer.LaunchAsync(options))11 {12 var page = await browser.NewPageAsync();13 await page.Mouse.ClickAsync(100, 100);14 await page.Mouse.MoveAsync(100, 100);15 await page.Mouse.DownAsync();16 await page.Mouse.MoveAsync(200, 200);17 await page.Mouse.UpAsync();18 await page.Mouse.MoveAsync(0, 0);19 await page.Touchscreen.TapAsync(100, 100);20 }21 }22 }23}24using PuppeteerSharp.Input;25using System;26using System.Threading.Tasks;27{28 {29 static async Task Main(string[] args)30 {31 {32 };33 using (var browser = await Puppeteer.LaunchAsync(options))34 {35 var page = await browser.NewPageAsync();36 await page.Mouse.ClickAsync(100, 100);37 await page.Mouse.MoveAsync(100, 100);38 await page.Mouse.DownAsync();39 await page.Mouse.MoveAsync(200, 200);40 await page.Mouse.UpAsync();41 await page.Mouse.MoveAsync(0, 0);42 await page.Touchscreen.TapAsync(100, 100);43 }44 }45 }46}47using PuppeteerSharp.Input;48using System;49using System.Threading.Tasks;50{51 {52 static async Task Main(string[] args)53 {54 {55 };56 using (

Full Screen

Full Screen

Touchscreen

Using AI Code Generation

copy

Full Screen

1using PuppeteerSharp.Input;2using System;3using System.Threading.Tasks;4{5 {6 static void Main(string[] args)7 {8 MainAsync().GetAwaiter().GetResult();9 }10 static async Task MainAsync()11 {12 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false }))13 {14 var page = await browser.NewPageAsync();15 await page.SetViewportAsync(new ViewPortOptions { Width = 1920, Height = 1080 });16 await page.Touchscreen.TapAsync(100, 100);17 }18 }19 }20}21using PuppeteerSharp.Input;22using System;23using System.Threading.Tasks;24{25 {26 static void Main(string[] args)27 {28 MainAsync().GetAwaiter().GetResult();29 }30 static async Task MainAsync()31 {32 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false }))33 {34 var page = await browser.NewPageAsync();35 await page.SetViewportAsync(new ViewPortOptions { Width = 1920, Height = 1080 });36 await page.Touchscreen.TapAsync(100, 100);37 }38 }39 }40}41using PuppeteerSharp.Input;42using System;43using System.Threading.Tasks;44{45 {46 static void Main(string[] args)47 {48 MainAsync().GetAwaiter().GetResult();49 }50 static async Task MainAsync()51 {52 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false }))53 {54 var page = await browser.NewPageAsync();55 await page.SetViewportAsync(new ViewPortOptions { Width = 1920, Height = 1080 });56 await page.Touchscreen.TapAsync(100, 100);57 }58 }59 }60}

Full Screen

Full Screen

Touchscreen

Using AI Code Generation

copy

Full Screen

1var touchscreen = new Touchscreen(page);2await touchscreen.TapAsync(100, 100);3var touchscreen = new Touchscreen(page);4await touchscreen.TapAsync(100, 100);5var touchscreen = new Touchscreen(page);6await touchscreen.TapAsync(100, 100);7var touchscreen = new Touchscreen(page);8await touchscreen.TapAsync(100, 100);9var touchscreen = new Touchscreen(page);10await touchscreen.TapAsync(100, 100);11var touchscreen = new Touchscreen(page);12await touchscreen.TapAsync(100, 100);13var touchscreen = new Touchscreen(page);14await touchscreen.TapAsync(100, 100);15var touchscreen = new Touchscreen(page);16await touchscreen.TapAsync(100, 100);17var touchscreen = new Touchscreen(page);18await touchscreen.TapAsync(100, 100);19var touchscreen = new Touchscreen(page);20await touchscreen.TapAsync(100, 100);21var touchscreen = new Touchscreen(page);22await touchscreen.TapAsync(100, 100);23var touchscreen = new Touchscreen(page);24await touchscreen.TapAsync(100, 100);25var touchscreen = new Touchscreen(page);26await touchscreen.TapAsync(100, 100

Full Screen

Full Screen

Touchscreen

Using AI Code Generation

copy

Full Screen

1var input = page.Keyboard;2await input.DownAsync("ControlLeft");3await input.DownAsync("KeyA");4await input.UpAsync("KeyA");5await input.UpAsync("ControlLeft");6var input = page.Keyboard;7await input.DownAsync("ControlLeft");8await input.DownAsync("KeyA");9await input.UpAsync("KeyA");10await input.UpAsync("ControlLeft");11var input = page.Keyboard;12await input.DownAsync("ControlLeft");13await input.DownAsync("KeyA");14await input.UpAsync("KeyA");15await input.UpAsync("ControlLeft");16var input = page.Keyboard;17await input.DownAsync("ControlLeft");18await input.DownAsync("KeyA");19await input.UpAsync("KeyA");20await input.UpAsync("ControlLeft");21var input = page.Keyboard;22await input.DownAsync("ControlLeft");23await input.DownAsync("KeyA");24await input.UpAsync("KeyA");25await input.UpAsync("ControlLeft");26var input = page.Keyboard;27await input.DownAsync("ControlLeft");28await input.DownAsync("KeyA");29await input.UpAsync("KeyA");30await input.UpAsync("ControlLeft");31var input = page.Keyboard;32await input.DownAsync("ControlLeft");33await input.DownAsync("KeyA");34await input.UpAsync("KeyA");35await input.UpAsync("ControlLeft");36var input = page.Keyboard;37await input.DownAsync("ControlLeft");38await input.DownAsync("KeyA");39await input.UpAsync("KeyA");40await input.UpAsync("ControlLeft");41var input = page.Keyboard;42await input.DownAsync("ControlLeft");43await input.DownAsync("KeyA");44await input.UpAsync("KeyA");

Full Screen

Full Screen

Touchscreen

Using AI Code Generation

copy

Full Screen

1var puppeteer = require('puppeteer');2var fs = require('fs');3var path = require('path');4var Touchscreen = require('puppeteer-sharp/lib/PuppeteerSharp/Input/Touchscreen');5var viewport = {6};7var browser = null;8var page = null;9var touchScreen = null;10var start = async function () {11 browser = await puppeteer.launch({12 });13 page = await browser.newPage();14 touchScreen = page.touchscreen;15 await page.setViewport(viewport);16 await page.waitForSelector('input[name="q"]');17 await page.type('input[name="q"]', 'puppeteer');18 await page.keyboard.press('Enter');19 await page.waitForNavigation();20 await page.waitForSelector('a[href="

Full Screen

Full Screen

Touchscreen

Using AI Code Generation

copy

Full Screen

1var device = new Models.DeviceDescriptors.IPhone6();2var options = new LaunchOptions { Headless = false, Args = new[] { "--touch-events=enabled" } };3var browser = await Puppeteer.LaunchAsync(options);4var page = await browser.NewPageAsync();5await page.EmulateAsync(device);6await page.Touchscreen.TapAsync(100, 100);7await page.ScreenshotAsync("1.png");8await browser.CloseAsync();9var device = new Models.DeviceDescriptors.IPhone6();10var options = new LaunchOptions { Headless = false, Args = new[] { "--touch-events=enabled" } };11var browser = await Puppeteer.LaunchAsync(options);12var page = await browser.NewPageAsync();13await page.EmulateAsync(device);14await page.Touchscreen.TapAsync(100, 100);15await page.ScreenshotAsync("2.png");16await browser.CloseAsync();17var device = new Models.DeviceDescriptors.IPhone6();18var options = new LaunchOptions { Headless = false, Args = new[] { "--touch-events=enabled" } };19var browser = await Puppeteer.LaunchAsync(options);20var page = await browser.NewPageAsync();21await page.EmulateAsync(device);22await page.Touchscreen.TapAsync(100, 100);23await page.ScreenshotAsync("3.png");24await browser.CloseAsync();25var device = new Models.DeviceDescriptors.IPhone6();26var options = new LaunchOptions { Headless = false, Args = new[] { "--touch-events=enabled" } };27var browser = await Puppeteer.LaunchAsync(options);28var page = await browser.NewPageAsync();29await page.EmulateAsync(device);30await page.Touchscreen.TapAsync(100, 100);31await page.ScreenshotAsync("4.png");32await browser.CloseAsync();

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in Touchscreen

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful