Best Puppeteer-sharp code snippet using PuppeteerSharp.Page.TapAsync
Index.cshtml.cs
Source:Index.cshtml.cs
...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)...
WebScraper.cs
Source:WebScraper.cs
...212 TapScreenAsync(target).Wait();213 }214 private async Task TapScreenAsync(string target)215 {216 await m_page.TapAsync(target);217 }218 /// <summary>219 /// Generates a pdf of the page.220 /// </summary>221 /// <returns>Stream containing the pdf data.</returns>222 public Stream CreatePdf()223 {224 var data = CreatePdfAsync();225 data.Wait();226 return data.Result;227 }228 private async Task<Stream> CreatePdfAsync()229 {230 return await m_page.PdfStreamAsync();...
Get-ScraperMobileVikings.cs
Source:Get-ScraperMobileVikings.cs
...4748 // Cookies49 var cookie = await page.WaitForSelectorAsync(50 "body > div:nth-child(1) > div:nth-child(1) > div.cookieWall.isVisible > div > div.cookieWall-ctas > button:nth-child(1)");51 await cookie.TapAsync();5253 // Login54 var loginField = await page.WaitForSelectorAsync("#loginName__0");55 await loginField.TypeAsync(EmailOrPhonenumber);56 var passwordField = await page.WaitForSelectorAsync("#password__1");57 await passwordField.TypeAsync(Password);58 var loginButton = await page.WaitForSelectorAsync(59 "body > div:nth-child(1) > div:nth-child(3) > div > div > main > section > div.loginBox > form > footer > button");60 System.Threading.Thread.Sleep(3000);61 await loginButton.TapAsync();62 await page.WaitForNavigationAsync();6364 // Get credits65 decimal credits;66 try {67 var creditField = await page.WaitForSelectorAsync(68 "body > div:nth-child(1) > div:nth-child(3) > div > div > main > div > section > div > section > section.MvSection.balanceItemSection > div > div > div:nth-child(2) > strong");69 var creditText = await creditField.EvaluateFunctionAsync<string>("e => e.innerText");70 var creditMatch = Regex.Match(creditText, @"^[^\d]*(\d+)[,\.](\d+)$");71 if (creditMatch.Success) {72 creditText = creditMatch.Groups[1].Value + CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator + (creditMatch.Groups[2].Value ?? "0");73 credits = decimal.Parse(creditText, CultureInfo.InvariantCulture.NumberFormat);74 } else {75 throw new Exception($"Credits not found ({creditText})");
...
Get-ScraperEtable.cs
Source:Get-ScraperEtable.cs
...4748 // Cookies49 var cookie = await page.WaitForSelectorAsync(50 "#username");51 await cookie.TapAsync();5253 // Login54 var loginField = await page.WaitForSelectorAsync("#username");55 await loginField.TypeAsync(Username);56 var passwordField = await page.WaitForSelectorAsync("#password");57 await passwordField.TypeAsync(Password);58 var loginButton = await page.WaitForSelectorAsync(59 "#login-form > div:nth-child(3) > div:nth-child(1) > div > button");60 await loginButton.TapAsync();61 await page.WaitForNavigationAsync();6263 await page.GoToAsync("https://e-table.be/admin/select-student.php");64 // System.Threading.Thread.Sleep(6000);65 //await page.WaitForNavigationAsync();66 await page.WaitForSelectorAsync("#student1");67 string link = null;68 for (int i = 0; i < 4; i++) {69 var studentSelector = await page.WaitForSelectorAsync($"#student{i+1}");70 var nameField = await page.WaitForSelectorAsync($"#student{i+1} > a > div > h5");71 var text = await nameField.EvaluateFunctionAsync<string>("e => e.innerText");72 Console.WriteLine(text);73 if (string.IsNullOrEmpty(StudentName) || string.Compare(text, StudentName, true) == 0)74 {
...
pay.cshtml.cs
Source:pay.cshtml.cs
...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}...
Touchscreen.cs
Source:Touchscreen.cs
...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.33 // This waits a frame before sending the tap.34 // @see https://crbug.com/61321935 await _client.SendAsync("Runtime.evaluate", new RuntimeEvaluateRequest36 {37 Expression = "new Promise(x => requestAnimationFrame(() => requestAnimationFrame(x)))",38 AwaitPromise = true39 }).ConfigureAwait(false);40 var touchPoints = new[] { new TouchPoint { X = Math.Round(x), Y = Math.Round(y) } };41 await _client.SendAsync("Input.dispatchTouchEvent", new InputDispatchTouchEventRequest42 {43 Type = "touchStart",44 TouchPoints = touchPoints,...
TapFunction.cs
Source:TapFunction.cs
...35 {36 var element = await page.QuerySelectorByXPath(selector);37 if (element != null)38 {39 await element.TapAsync();40 }41 else42 {43 throw new Exception($"Node not found with '{selector}' selector on tap function");44 }45 }46 else47 {48 await page.TapAsync(selector); 49 }50 }51 else52 {53 var currentFrame = page.Frames.FirstOrDefault(x => x.Name == frame);54 if (currentFrame != null)55 {56 if (selector.StartsWith(XPathSelector.XPathSelectorToken))57 {58 var element = await currentFrame.QuerySelectorByXPath(selector);59 if (element != null)60 {61 await element.TapAsync();62 }63 else64 {65 throw new Exception($"Node not found with '{selector}' selector on tap function");66 }67 }68 else69 {70 await page.TapAsync(selector); 71 }72 }73 else74 {75 throw new Exception($"Frame not found with name '{frame}'");76 }77 }78 }79 #endregion80 }81}...
TouchScreenTests.cs
Source:TouchScreenTests.cs
...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}...
TapAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {8 var options = new LaunchOptions { Headless = false };9 using (var browser = await Puppeteer.LaunchAsync(options))10 {11 using (var page = await browser.NewPageAsync())12 {13 await page.TypeAsync("input[title='Search']", "Puppeteer");14 await page.TapAsync("input[value='Google Search']");15 }16 }17 }18 }19}
TapAsync
Using AI Code Generation
1using PuppeteerSharp;2using System.Threading.Tasks;3{4 {5 static void Main(string[] args)6 {7 MainAsync().Wait();8 }9 static async Task MainAsync()10 {11 var options = new LaunchOptions { Headless = false };12 using (var browser = await Puppeteer.LaunchAsync(options))13 {14 var page = await browser.NewPageAsync();15 await page.TypeAsync("input[name='q']", "PuppeteerSharp");16 await page.Keyboard.TapAsync("Enter");17 await page.WaitForNavigationAsync();18 }19 }20 }21}22using PuppeteerSharp;23using System.Threading.Tasks;24{25 {26 static void Main(string[] args)27 {28 MainAsync().Wait();29 }30 static async Task MainAsync()31 {32 var options = new LaunchOptions { Headless = false };33 using (var browser = await Puppeteer.LaunchAsync(options))34 {35 var page = await browser.NewPageAsync();36 await page.TypeAsync("input[name='q']", "PuppeteerSharp");37 await page.Keyboard.TapAsync("Enter");38 await page.WaitForNavigationAsync();39 }40 }41 }42}43using PuppeteerSharp;44using System.Threading.Tasks;45{46 {47 static void Main(string[] args)48 {49 MainAsync().Wait();50 }51 static async Task MainAsync()52 {53 var options = new LaunchOptions { Headless = false };54 using (var browser = await Puppeteer.LaunchAsync(options))55 {56 var page = await browser.NewPageAsync();57 await page.TypeAsync("input[name='q']", "PuppeteerSharp");58 await page.Keyboard.TapAsync("Enter");59 await page.WaitForNavigationAsync();60 }61 }62 }63}64using PuppeteerSharp;
TapAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 public static async Task Run()7 {8 var options = new LaunchOptions { Headless = false };9 using (var browser = await Puppeteer.LaunchAsync(options))10 using (var page = await browser.NewPageAsync())11 {12 await page.TypeAsync("input[name='q']", "PuppeteerSharp");13 await page.TapAsync("input[name='q']");14 await page.WaitForSelectorAsync("input[name='btnK']");15 await page.TapAsync("input[name='btnK']");16 }17 }18 }19}20using System;21using System.Threading.Tasks;22using PuppeteerSharp;23{24 {25 public static async Task Run()26 {27 var options = new LaunchOptions { Headless = false };28 using (var browser = await Puppeteer.LaunchAsync(options))29 using (var page = await browser.NewPageAsync())30 {31 await page.TypeAsync("input[name='q']", "PuppeteerSharp");32 await page.TapAsync("input[name='q']");33 await page.WaitForSelectorAsync("input[name='btnK']");34 await page.TapAsync("input[name='btnK']");35 }36 }37 }38}39using System;40using System.Threading.Tasks;41using PuppeteerSharp;42{43 {44 public static async Task Run()45 {46 var options = new LaunchOptions { Headless = false };47 using (var browser = await Puppeteer.LaunchAsync(options))48 using (var page = await browser.NewPageAsync())49 {50 await page.TypeAsync("input[name='q']", "PuppeteerSharp");51 await page.TapAsync("input[name='q']");52 await page.WaitForSelectorAsync("input[name='btnK']");53 await page.TapAsync("input[name='btnK']");54 }55 }
TapAsync
Using AI Code Generation
1await page.ClickAsync("input[name=q]");2await page.Keyboard.TypeAsync("PuppeteerSharp");3await page.Keyboard.DownAsync("Enter");4await page.Keyboard.UpAsync("Enter");5await page.WaitForNavigationAsync();6await page.ScreenshotAsync("screenshot.png");7await page.ClickAsync("input[name=q]");8await page.Keyboard.TypeAsync("PuppeteerSharp");9await page.Keyboard.TapAsync("Enter");10await page.WaitForNavigationAsync();11await page.ScreenshotAsync("screenshot.png");12await page.ClickAsync("input[name=q]");13await page.Keyboard.TypeAsync("PuppeteerSharp");14await page.Keyboard.TapAsync("Enter");15await page.WaitForNavigationAsync();16await page.ScreenshotAsync("screenshot.png");17await page.ClickAsync("input[name=q]");18await page.Keyboard.TypeAsync("PuppeteerSharp");19await page.Keyboard.TapAsync("Enter");20await page.WaitForNavigationAsync();21await page.ScreenshotAsync("screenshot.png");22await page.ClickAsync("input[name=q]");23await page.Keyboard.TypeAsync("PuppeteerSharp");24await page.Keyboard.TapAsync("Enter");25await page.WaitForNavigationAsync();26await page.ScreenshotAsync("screenshot.png");27await page.ClickAsync("input[name=q]");28await page.Keyboard.TypeAsync("PuppeteerSharp");29await page.Keyboard.TapAsync("Enter");30await page.WaitForNavigationAsync();31await page.ScreenshotAsync("screenshot.png");32await page.ClickAsync("
TapAsync
Using AI Code Generation
1public async Task TapAsync(string selector, TapOptions options = null)2{3 var element = await this.QuerySelectorAsync(selector);4 if (element == null)5 {6 throw new PuppeteerException($"No node found for selector: {selector}");7 }8 await element.TapAsync(options);9}10public async Task TapAsync(TapOptions options = null)11{12 await this.EvaluateFunctionAsync("element => element.click()", options);13}14public async Task TapAsync(string selector, TapOptions options = null)15{16 var element = await this.QuerySelectorAsync(selector);17 if (element == null)18 {19 throw new PuppeteerException($"No node found for selector: {selector}");20 }21 await element.TapAsync(options);22}23public async Task TapAsync(TapOptions options = null)24{25 await this.EvaluateFunctionAsync("element => element.click()", options);26}27public async Task TapAsync(string selector, TapOptions options = null)28{29 var element = await this.QuerySelectorAsync(selector);30 if (element == null)31 {32 throw new PuppeteerException($"No node found for selector: {selector}");33 }34 await element.TapAsync(options);35}36public async Task TapAsync(TapOptions options = null)37{38 await this.EvaluateFunctionAsync("element => element.click()", options);39}40public async Task TapAsync(string selector, TapOptions options = null)41{42 var element = await this.QuerySelectorAsync(selector);43 if (element == null)44 {45 throw new PuppeteerException($"No node found for selector: {selector}");46 }47 await element.TapAsync(options);48}49public async Task TapAsync(TapOptions options = null)
TapAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static void Main(string[] args)7 {8 MainAsync().GetAwaiter().GetResult();9 }10 static async Task MainAsync()11 {12 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);13 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false }))14 using (var page = await browser.NewPageAsync())15 {16 await page.ScreenshotAsync("google.png");17 await page.ClickAsync("input[name='q']");18 await page.Keyboard.TypeAsync("PuppeteerSharp");19 await page.Keyboard.PressAsync("Enter");20 await page.WaitForNavigationAsync();21 await page.ScreenshotAsync("google-result.png");22 var text = await page.EvaluateExpressionAsync<string>("document.querySelector('input[name=\"q\"]').value");23 Console.WriteLine(text);24 await page.ClickAsync("input[name='btnK']");25 await page.WaitForNavigationAsync();26 var text2 = await page.EvaluateExpressionAsync<string>("document.querySelector('input[name=\"btnK\"]').value");27 Console.WriteLine(text2);28 await page.ClickAsync("input[name='btnK']");29 await page.WaitForNavigationAsync();30 var text3 = await page.EvaluateExpressionAsync<string>("document.querySelector('input[name=\"btnK\"]').value");31 Console.WriteLine(text3);32 await page.ClickAsync("input[name='btnK']");33 await page.WaitForNavigationAsync();34 var text4 = await page.EvaluateExpressionAsync<string>("document.querySelector('input[name=\"btnK\"]').value");35 Console.WriteLine(text4);36 await page.ClickAsync("input[name='btn
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!