How to use ClickAsync method of PuppeteerSharp.Input.Mouse class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Input.Mouse.ClickAsync

PageServer.cs

Source:PageServer.cs Github

copy

Full Screen

...175 await page.GoToAsync(Url);176 await page.WaitForTimeoutAsync(500);177 await GetPhoneCode(Phone, page);178 var seven = await page.EvaluateExpressionAsync("document.querySelectorAll('button[report-eventid=MLoginRegister_SMSReceiveCode]')[0].innerText");179 await page.ClickAsync("button[report-eventid='MLoginRegister_SMSReceiveCode']");180 await page.ClickAsync("input[type=checkbox]");181 await page.WaitForTimeoutAsync(500);182 string js = "document.body.outerText";183 var pageouterText = await page.EvaluateExpressionAsync(js);184 var pagetext = pageouterText.ToString();185 var data = await getCount(qlkey);186 if (pagetext.Contains("安全验证") && !pagetext.Contains("验证成功"))187 {188 Console.WriteLine(Phone + "安全验证");189 // await PageClose(Phone);190 result.data = new { Status = 666,ckcount = data.ckcount, tabcount = data.tabcount };191 result.message = "出现安全验证,";192 return result;193 }194 if (pagetext.Contains("短信验证码发送次数已达上限"))195 {196 await PageClose(Phone);197 result.data = new { Status = 505, pagetext = pagetext };198 result.message = "对不起,短信验证码发送次数已达上限,请24小时后再试。";199 return result;200 }201 if (pagetext.Contains("该手机号未注册,将为您直接注册。"))202 {203 await PageClose(Phone);204 result.data = new { Status = 501 };205 result.message = "该手机号未注册";206 return result;207 }208 Console.WriteLine(" 手机:" + Phone + " tabe 创建 时间:" + DateTime.Now.ToString());209 System.Timers.Timer timer = new System.Timers.Timer(60000 * 3);210 timer.Elapsed += new System.Timers.ElapsedEventHandler(async (s, e) =>211 {212 Console.WriteLine(" 手机:" + Phone + " tabe 自动回收 时间:" + DateTime.Now.ToString());213 Delpage(Phone, page);214 await page.CloseAsync();215 var oldpage = GetPage();216 if (oldpage == null)217 {218 await browser.CloseAsync();219 }220 timer.Dispose();221 });222 timer.AutoReset = false;223 timer.Start();224 225 result.data = new { ckcount = data.ckcount, tabcount = data.tabcount };226 result.success = true;227 return result;228 }229 public async Task PageClose(string Phone)230 {231 var page = GetPage(Phone);232 if (page != null)233 {234 Delpage(Phone, page);235 var browser = page.Browser;236 await page.CloseAsync();237 var oldpage = GetPage();238 if (oldpage == null)239 {240 await browser.CloseAsync();241 }242 }243 }244 public async Task ReSendSmSCode(string Phone)245 {246 var page = GetPage(Phone);247 if (page == null) throw new Exception("页面未找到,可能超时回收了.请刷新页面重新登录");248 await GetPhoneCode(Phone, page);249 }250 public async Task<ResultModel<object>> VerifyCode(int qlkey, string Phone, string Code)251 {252 try253 {254 ResultModel<object> result = ResultModel<object>.Create(false, "");255 var qlconfig = _mainConfig.GetConfig(qlkey);256 if (qlconfig == null)257 {258 result.message = "未找到相应的服务器配置。请刷新页面后再试";259 result.data = new { Status = 404 };260 return result;261 }262 Page page = GetPage(Phone);263 if (page == null)264 {265 result.message = "未找到当前号码的网页请稍候再试,或者网页超过3分钟已被回收";266 result.data = new { Status = 404 };267 return result;268 }269 await SetCode(Code, page);270 Console.WriteLine("输入验证码" + Code);271 Console.WriteLine(page.Url);272 await page.ClickAsync("a[report-eventid='MLoginRegister_SMSLogin']");273 // 274 await page.WaitForTimeoutAsync(2500);275 string js = "document.body.outerText";276 var pageouterText = await page.EvaluateExpressionAsync(js);277 var pagetext = pageouterText.ToString();278 // Console.WriteLine(pagetext.ToString());279 if (pagetext.Contains("验证码输入错误"))280 {281 result.message = "验证码输入错误";282 return result;283 }284 if (pagetext.Contains("验证码错误多次,请重新获取"))285 {286 await PageClose(Phone);287 result.data = new { Status = 501 };288 result.message = "验证码错误多次,请过三分钟之后再来。";289 return result;290 }291 if (pagetext.Contains("该手机号未注册,将为您直接注册。"))292 {293 await PageClose(Phone);294 result.data = new { Status = 501 };295 result.message = "该手机号未注册";296 return result;297 }298 await page.WaitForTimeoutAsync(2500);299 var cookies = await page.GetCookiesAsync();300 var CKkey = cookies.FirstOrDefault(x => x.Name == "pt_key");301 var CKpin = cookies.FirstOrDefault(x => x.Name == "pt_pin");302 if (CKkey == null || CKpin == null)303 {304 await PageClose(Phone);305 result.message = "获取Cookie失败,请重试";306 result.data = new { Status = 404 };307 return result;308 }309 int MAXCount = qlconfig.QL_CAPACITY;310 var CCookie = CKkey.Name + "=" + CKkey.Value + ";" + CKpin.Name + "=" + CKpin.Value + ";";311 var Nickname = "";312 Nickname = await GetNickname(CCookie);313 JArray data = await qlconfig.GetEnv();314 var env = data.FirstOrDefault(x => x["value"].ToString().Contains("pt_pin=" + CKpin.Value + ";"));315 var QLCount = data.Count;316 317 string QLId = "";318 string timestamp = "";319 if (env == null)320 {321 if (QLCount >= MAXCount)322 {323 result.message = "你来晚了,没有多余的位置了";324 result.data = new { Status = 501 };325 return result;326 }327 328 var addresult = await qlconfig.AddEnv(CCookie, Nickname);329 JObject addUser = (JObject)addresult.data[0];330 QLId = addUser["_id"].ToString();331 timestamp = addUser["timestamp"].ToString();332 }333 else334 {335 QLId = env["_id"].ToString();336 if(env["remarks"] != null)337 Nickname = env["remarks"].ToString();338 339 var upresult = await qlconfig.UpdateEnv(CCookie, QLId, Nickname);340 timestamp = upresult.data["timestamp"].ToString();341 }342 var qin = await getCount(qlkey);343 await PageClose(Phone);344 result.success = true;345 result.data = new { qlid = QLId, nickname = Nickname, timestamp = timestamp, remarks = Nickname, qlkey = qlconfig.QLkey, ckcount = qin.ckcount, tabcount = qin.tabcount };346 return result;347 }catch(Exception e)348 {349 Console.WriteLine(e.ToString());350 throw e;351 }352 353 }354 public async Task<(int ckcount, int tabcount)> getCount(int qlkey)355 {356 var config = _mainConfig.GetConfig(qlkey);357 var qlcount = await config.GetEnvsCount();358 var ckcount = config.QL_CAPACITY - qlcount;359 string MaxTab = _mainConfig.MaxTab;360 var intabcount = GetPageCount();361 int tabcount = int.Parse(MaxTab) - intabcount;362 return (ckcount, tabcount);363 }364 private async Task Setphone(string phone, Page page)365 {366 string jq = @"document.querySelectorAll('input[report-eventid=MLoginRegister_SMSPhoneInput]')[0].value='';";367 await page.EvaluateExpressionAsync(jq);368 System.Threading.Thread.Sleep(500);369 await page.TypeAsync("input[report-eventid=MLoginRegister_SMSPhoneInput]", phone);370 System.Threading.Thread.Sleep(500);371 }372 private async Task<bool> GetPhoneCode(string Phone, Page page)373 {374 page = AddPage(Phone, page);375 await Setphone(Phone, page);376 var CodeBtn = await page.XPathAsync("//button[@report-eventid='MLoginRegister_SMSReceiveCode']");377 var CodeProperties = await CodeBtn[0].GetPropertiesAsync();378 var CodeBtnClasses = CodeProperties["_prevClass"].ToString().Split(" ");379 bool canSendCode = CodeBtnClasses.Contains("active");380 if (canSendCode)381 {382 return true;383 }384 else385 {386 await page.ReloadAsync();387 System.Threading.Thread.Sleep(500);388 return await GetPhoneCode(Phone, page);389 }390 }391 private long GetTime()392 {393 TimeSpan ts = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1);//ToUniversalTime()转换为标准时区的时间,去掉的话直接就用北京时间394 return (long)ts.TotalSeconds;395 }396 private async Task<string> GetNickname(string cookie)397 {398 try399 {400 var url = @"https://me-api.jd.com/user_new/info/GetJDUserInfoUnion?orgFlag=JD_PinGou_New&callSource=mainorder&channel=4&isHomewhite=0&sceneval=2&_=" + GetTime() + "&sceneval=2&g_login_type=1&g_ty=ls";401 using (HttpClient client = new HttpClient())402 {403 client.DefaultRequestHeaders.Add("Cookie", cookie);404 client.DefaultRequestHeaders.Add("Referer", "https://home.m.jd.com/myJd/newhome.action");405 client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36");406 client.DefaultRequestHeaders.Add("Host", "me-api.jd.com");407 var result = await client.GetAsync(url);408 string resultContent = result.Content.ReadAsStringAsync().Result;409 // Console.WriteLine(resultContent);410 JObject j = JObject.Parse(resultContent);411 // data?.userInfo.baseInfo.nickname412 return j["data"]["userInfo"]["baseInfo"]["nickname"].ToString();413 }414 }415 catch(Exception e)416 {417 return "未知";418 }419 420 }421 private static async Task SetCode(string Code, Page page)422 {423 await page.ClickAsync("#authcode", new PuppeteerSharp.Input.ClickOptions { ClickCount = 3 });424 System.Threading.Thread.Sleep(500);425 await page.TypeAsync("#authcode", Code);426 System.Threading.Thread.Sleep(500);427 }428 public async Task<ResultModel<object>> AutoCaptcha(string Phone)429 {430 Console.WriteLine(Phone + "安全验证破解");431 var page = GetPage(Phone);432 var cpc_img = await page.QuerySelectorAsync("#cpc_img");433 var cpc_imgheader = await cpc_img.GetPropertyAsync("src");434 var cpc_imgsrc = await cpc_imgheader.JsonValueAsync();435 var small_img = await page.QuerySelectorAsync("#small_img");436 var small_imgheader = await small_img.GetPropertyAsync("src");437 var small_imgsrc = await small_imgheader.JsonValueAsync();...

Full Screen

Full Screen

PuppeteerWebAutomationFrameworkInstance.cs

Source:PuppeteerWebAutomationFrameworkInstance.cs Github

copy

Full Screen

...35 .Aggregate(string.Empty, (a, b) => $"{a}, {b}")36 .TrimStart(',', ' ');37 return await _page.QuerySelectorAllAsync(selector);38 }39 public async Task ClickAsync(IReadOnlyList<IDomElement> elements, int? offsetX, int? offsetY)40 {41 foreach (var element in elements)42 {43 await _page.Mouse.ClickAsync(44 (element.BoundingClientRectangle.Left + offsetX) ?? element.BoundingClientRectangle.Center.X,45 (element.BoundingClientRectangle.Top + offsetY) ?? element.BoundingClientRectangle.Center.Y);46 }47 }48 public Task DisposeAsync()49 {50 _isDisposed = true;51 if (_page != null)52 {53 _page.Request -= PageRequest;54 _page.RequestFinished -= PageRequestFinished;55 _page.RequestFailed -= PageRequestFinished;56 _page?.Dispose();57 }58 _browser?.Dispose();59 return Task.CompletedTask;60 }61 public async Task DoubleClickAsync(IReadOnlyList<IDomElement> elements, int? offsetX, int? offsetY)62 {63 foreach (var element in elements)64 {65 await _page.Mouse.ClickAsync(66 (element.BoundingClientRectangle.Left + offsetX) ?? element.BoundingClientRectangle.Center.X,67 (element.BoundingClientRectangle.Top + offsetY) ?? element.BoundingClientRectangle.Center.Y,68 new ClickOptions()69 {70 ClickCount = 271 });72 }73 }74 public async Task DragDropAsync(75 IDomElement from,76 int? fromOffsetX,77 int? fromOffsetY,78 IDomElement to,79 int? toOffsetX,80 int? toOffsetY)81 {82 var javascriptScope = _domTunnel.DeclareScope(this);83 try84 {85 var dataTransferObjectVariableName = await javascriptScope.CreateNewVariableAsync("new DataTransfer()");86 await _page.Mouse.MoveAsync(87 (from.BoundingClientRectangle.Left + fromOffsetX) ?? from.BoundingClientRectangle.Center.X,88 (from.BoundingClientRectangle.Top + fromOffsetY) ?? from.BoundingClientRectangle.Center.Y);89 await _page.Mouse.DownAsync();90 await _domTunnel.DispatchDomElementDragEventAsync(91 this,92 from,93 "dragstart",94 dataTransferObjectVariableName);95 await _domTunnel.DispatchDomElementDragEventAsync(96 this,97 from,98 "drag",99 dataTransferObjectVariableName);100 await _page.Mouse.MoveAsync(101 (to.BoundingClientRectangle.Left + toOffsetX) ?? to.BoundingClientRectangle.Center.X,102 (to.BoundingClientRectangle.Top + toOffsetY) ?? to.BoundingClientRectangle.Center.Y);103 await _domTunnel.DispatchDomElementDragEventAsync(104 this,105 to,106 "dragenter",107 dataTransferObjectVariableName);108 await _domTunnel.DispatchDomElementDragEventAsync(109 this,110 to,111 "dragover",112 dataTransferObjectVariableName);113 await _domTunnel.DispatchDomElementDragEventAsync(114 this,115 from,116 "drag",117 dataTransferObjectVariableName);118 await _page.Mouse.UpAsync();119 await _domTunnel.DispatchDomElementDragEventAsync(120 this,121 to,122 "dragleave",123 dataTransferObjectVariableName);124 await _domTunnel.DispatchDomElementDragEventAsync(125 this,126 from,127 "dragend",128 dataTransferObjectVariableName);129 await _domTunnel.DispatchDomElementDragEventAsync(130 this,131 to,132 "drop",133 dataTransferObjectVariableName);134 }135 finally136 {137 await javascriptScope.DeleteAllVariablesAsync();138 }139 }140 public async Task EnterTextInAsync(IReadOnlyList<IDomElement> elements, string text)141 {142 var handles = await GetElementHandlesFromDomElementsAsync(elements);143 foreach (var handle in handles)144 {145 await handle.TypeAsync(text);146 }147 }148 public async Task<string> EvaluateJavaScriptExpressionAsync(string code)149 {150 while (true)151 {152 try153 {154 while (IsNavigating)155 await Task.Delay(100);156 var blob = await _page.EvaluateExpressionAsync(code);157 return blob?.ToString();158 }159 catch (PuppeteerException)160 {161 if(!IsNavigating)162 throw;163 }164 }165 }166 public async Task<IReadOnlyList<IDomElement>> FindDomElementsBySelectorAsync(int methodChainOffset, string selector)167 {168 if (_isDisposed)169 return new List<IDomElement>();170 return await _domTunnel.GetDomElementsFromSelector(this,171 methodChainOffset,172 selector);173 }174 public async Task FocusAsync(IDomElement domElement)175 {176 var handle = await GetElementHandleFromDomElementAsync(domElement);177 await handle.FocusAsync();178 //there is a bug causing Puppeteer to not focus input elements properly - so we invoke their onfocus events manually.179 if (domElement.TagName == "INPUT" && domElement.Attributes["type"] == "text")180 {181 await _domTunnel.DispatchDomElementFocusEventAsync(182 this,183 domElement,184 "focus");185 }186 }187 private async Task<ElementHandle> GetElementHandleFromDomElementAsync(IDomElement domElement)188 {189 return await _page.QuerySelectorAsync(domElement.CssSelector);190 }191 public async Task HoverAsync(IDomElement domElement, int? offsetX, int? offsetY)192 {193 await _page.Mouse.MoveAsync(194 (domElement.BoundingClientRectangle.Left + offsetX) ?? domElement.BoundingClientRectangle.Center.X,195 (domElement.BoundingClientRectangle.Top + offsetY) ?? domElement.BoundingClientRectangle.Center.Y);196 }197 public async Task InitializeAsync()198 {199 _browser = await _driverConstructor();200 var pages = await _browser.PagesAsync();201 _page = pages.Single();202 await _page.SetCacheEnabledAsync(false);203 _page.Request += PageRequest;204 _page.RequestFinished += PageRequestFinished;205 _page.RequestFailed += PageRequestFinished;206 }207 private void PageRequestFinished(object sender, RequestEventArgs e)208 {209 if (!e.Request.IsNavigationRequest)210 return;211 Interlocked.Decrement(ref _pendingNavigationRequestCount);212 }213 private void PageRequest(object sender, RequestEventArgs e)214 {215 if (!e.Request.IsNavigationRequest)216 return;217 Interlocked.Increment(ref _pendingNavigationRequestCount);218 }219 public async Task OpenAsync(string uri)220 {221 await _page.GoToAsync(uri);222 }223 public async Task RightClickAsync(IReadOnlyList<IDomElement> elements, int? offsetX, int? offsetY)224 {225 foreach (var element in elements)226 {227 await _page.Mouse.ClickAsync(228 (element.BoundingClientRectangle.Left + offsetX) ?? element.BoundingClientRectangle.Center.X,229 (element.BoundingClientRectangle.Top + offsetY) ?? element.BoundingClientRectangle.Center.Y,230 new ClickOptions()231 {232 Button = MouseButton.Right233 });234 }235 }236 public async Task SelectByIndicesAsync(IReadOnlyList<IDomElement> elements, int[] byIndices)237 {238 foreach (var element in elements)239 {240 var selector = byIndices241 .Select(x => $"{element.CssSelector} > option:nth-child({x + 1})")...

Full Screen

Full Screen

Index.cshtml.cs

Source:Index.cshtml.cs Github

copy

Full Screen

...193 //await page.EmulateAsync(Puppeteer.Devices[DeviceDescriptorName.IPhone8Plus]);194 //await page.GoToAsync("https://upay.10010.com/jf_wxgz");195 //await page.SetCookieAsync(new CookieParam { Name = "key", Value = "value", SameSite = SameSite.None, Secure = true });196 //string phone = "13113075869";197 //await page.ClickAsync("#number");198 //await page.TypeAsync("#number", phone);199 //Thread.Sleep(3000);200 //await page.ClickAsync("#cardlist > section > div.mobile-cardlist.cardlista > a:nth-child(1)");201 //await browser.CloseAsync();202 //await browser.DisposeAsync();203 //await page.EvaluateExpressionAsync($"document.getElementById('number').value={phone}");204 //var input = await page.("#number", "13113075869");205 //await input.EvaluateFunctionAsync("#number", "131125836985");206 //await page.ScreenshotAsync(outputFile);207 }208 }209}...

Full Screen

Full Screen

WebScraper.cs

Source:WebScraper.cs Github

copy

Full Screen

...171 /// </summary>172 /// <param name="button">Mouse button to simulate.</param>173 public void MouseClick(MouseButton button)174 {175 MouseClickAsync(button).Wait();176 }177 private async Task MouseClickAsync(MouseButton button)178 {179 await m_page.Mouse.ClickAsync(m_MouseX, m_MouseY, new ClickOptions{ Button = button == MouseButton.Left ? PuppeteerSharp.Input.MouseButton.Left : PuppeteerSharp.Input.MouseButton.Right });180 }181 /// <summary>182 /// Simulates a mouse up event on page.183 /// </summary>184 /// <param name="button">Mouse button to simulate.</param>185 public void MouseUp(MouseButton button)186 {187 MouseUpAsync(button).Wait();188 189 }190 private async Task MouseUpAsync(MouseButton button)191 {192 await m_page.Mouse.UpAsync(new ClickOptions { Button = button == MouseButton.Left ? PuppeteerSharp.Input.MouseButton.Left : PuppeteerSharp.Input.MouseButton.Right });193 }194 /// <summary>195 /// Simulates a mouse down event on page.196 /// </summary>197 /// <param name="button">Mouse button to simulate.</param>198 public void MouseDown(MouseButton button)199 {200 MouseDownAsync(button).Wait();201 }202 private async Task MouseDownAsync(MouseButton button)203 {204 await m_page.Mouse.DownAsync(new ClickOptions { Button = button == MouseButton.Left ? PuppeteerSharp.Input.MouseButton.Left : PuppeteerSharp.Input.MouseButton.Right });205 }206 /// <summary>207 /// Simulates a touch tap on a page.208 /// </summary>209 /// <param name="target">Javascript selector for element to tap on.</param>210 public void TapScreen(string target)211 {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();231 }232 /// <summary>233 /// Waits for expression to be to be true.234 /// </summary>235 /// <param name="expression">Expression to wait on.</param>236 public void WaitOnScript(string expression)237 {238 WaitOnScriptAsync(expression).Wait();239 }240 private async Task WaitOnScriptAsync(string expression)241 {242 await m_page.WaitForExpressionAsync(expression);243 }244 /// <summary>245 /// Selects element on page to have focus.246 /// </summary>247 /// <param name="target">Javascript selector to make have focus.</param>248 public void Focus(string target)249 {250 FocusAsync(target).Wait();251 }252 private async Task FocusAsync(string target)253 {254 await m_page.FocusAsync(target);255 }256 /// <summary>257 /// Clicks on target element on page.258 /// </summary>259 /// <param name="target">Javascript selector of element to click on.</param>260 public void Click(string target)261 {262 ClickAsync(target).Wait();263 }264 private async Task ClickAsync(string target)265 {266 await m_page.ClickAsync(target);267 }268 /// <summary>269 /// Html content of page. Useful for scraping the html directly.270 /// </summary>271 public string Content272 {273 get274 {275 var data = m_page.GetContentAsync();276 data.Wait();277 return data.Result;278 }279 set280 {...

Full Screen

Full Screen

ClickFunction.cs

Source:ClickFunction.cs Github

copy

Full Screen

...101 {102 var element = await page.QuerySelectorByXPath(selector);103 if (element != null)104 {105 await element.ClickAsync();106 }107 else108 {109 throw new Exception($"Node not found with '{selector}' selector on click function");110 }111 }112 else113 {114 await page.ClickAsync(selector, clickOptions); 115 } 116 }117 else118 {119 var currentFrame = page.Frames.FirstOrDefault(x => x.Name == frame);120 if (currentFrame != null)121 {122 if (selector.StartsWith(XPathSelector.XPathSelectorToken))123 {124 var element = await currentFrame.QuerySelectorByXPath(selector);125 if (element != null)126 {127 await element.ClickAsync();128 }129 else130 {131 throw new Exception($"Node not found with '{selector}' selector on click function");132 }133 }134 else135 {136 await currentFrame.ClickAsync(selector, clickOptions); 137 }138 }139 else140 {141 throw new Exception($"Frame not found with name '{frame}'");142 }143 }144 }145 146 private async Task ClickCoordinateAsync(Page page, int x, int y, ClickOptions clickOptions)147 {148 await page.Mouse.ClickAsync(x, y, clickOptions);149 }150 #endregion151 }152}

Full Screen

Full Screen

pay.cshtml.cs

Source:pay.cshtml.cs Github

copy

Full Screen

...32 await page.EvaluateFunctionOnNewDocumentAsync("() =>{ Object.defineProperty(navigator, 'plugins', { get: () => [1, 2, 3, 4, 5,6], }); }");33 Console.WriteLine(await page.EvaluateExpressionAsync("navigator.webdriver"));34 //ÌîдÊÖ»úºÅÂë35 string phone = "13113075869";36 await page.ClickAsync("#number");37 await page.TypeAsync("#number", phone);38 Thread.Sleep(1000);39 //µã»÷³äÖµ°´Å¥40 await page.ClickAsync("#cardlist > section > div.mobile-cardlist.cardlista > a:nth-child(1)");41 ElementHandle slideBtn = null;42 try43 {44 slideBtn = await page.WaitForSelectorAsync("#nc_1_n1t", new WaitForSelectorOptions { Timeout = 3 * 1000 });45 }46 catch (Exception ex)47 {48 var msg = ex.Message;49 }50 if (slideBtn != null)51 {52 var rect = await slideBtn.BoundingBoxAsync();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

IPuppeteerBrowser.cs

Source:IPuppeteerBrowser.cs Github

copy

Full Screen

...16 Task<Page> WaitGetPage(Page page, string selector, string targetId);17 Task<Page> ClickAndGetPage(ElementHandle element, string targetId);18 Task<Page> ClickAndGetPage(ElementHandle element, string targetId, WaitForOptions waitForOptions);19 Task<string> GetContentAsync(Page page);20 Task ClickAsync(Page page, string clickPlace, ClickOptions clickOptions = null);21 Task<string> GetFramePage(string iframeSrc);22 Task<string> GetFramePage(Page page, string frameName);23 Task<string> GetVideoAdsOnUrl(Page page, string xPath);24 Task<string> GetScrolledPage(string videoUrl, int maxScroll, params WaitUntilNavigation[] waitUntilNavigations);25 Task<string> GetPagePermission(Page page, string permissionName);26 Task<string> ClickButtonForContinue(Page page, string buttonXPath, string adUrl,27 params WaitUntilNavigation[] waitUntilNavigations);28 /// <summary>29 /// Returns IpDetails by the specified url30 /// </summary>31 /// <param name="ipFetcherUrl">The ip details provider url.</param>32 /// <returns>The instance of <see cref="IpDetails"></see></returns>33 Task<IpDetails> GetIpDetails(string ipFetcherUrl);34 /// <summary>...

Full Screen

Full Screen

MouseButton.cs

Source:MouseButton.cs Github

copy

Full Screen

2using Newtonsoft.Json.Converters;3namespace PuppeteerSharp.Input4{5 /// <summary>6 /// The type of button click to use with <see cref="Mouse.DownAsync(ClickOptions)"/>, <see cref="Mouse.UpAsync(ClickOptions)"/> and <see cref="Mouse.ClickAsync(decimal, decimal, ClickOptions)"/>7 /// </summary>8 [JsonConverter(typeof(StringEnumConverter), true)] 9 public enum MouseButton10 {11 /// <summary>12 /// Non specified13 /// </summary>14 None,15 /// <summary>16 /// The left mouse button17 /// </summary>18 Left,19 /// <summary>20 /// The right mouse button...

Full Screen

Full Screen

ClickAsync

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {8 var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false });9 var page = await browser.NewPageAsync();10 await page.ClickAsync("input[name='q']");11 await page.Keyboard.PressAsync("PuppeteerSharp");12 await page.Keyboard.PressAsync("Enter");13 await page.ScreenshotAsync("example.png");14 await browser.CloseAsync();15 }16 }17}18using System;19using System.Threading.Tasks;20using PuppeteerSharp;21{22 {23 static async Task Main(string[] args)24 {

Full Screen

Full Screen

ClickAsync

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

ClickAsync

Using AI Code Generation

copy

Full Screen

1await page.Mouse.ClickAsync(10, 10);2await page.Touchscreen.ClickAsync(10, 10);3await page.Mouse.ClickAsync(10, 10);4await page.Touchscreen.ClickAsync(10, 10);5await page.Mouse.ClickAsync(10, 10);6await page.Touchscreen.ClickAsync(10, 10);7await page.Mouse.ClickAsync(10, 10);8await page.Touchscreen.ClickAsync(10, 10);9await page.Mouse.ClickAsync(10, 10);10await page.Touchscreen.ClickAsync(10, 10);11await page.Mouse.ClickAsync(10, 10);12await page.Touchscreen.ClickAsync(10, 10);13await page.Mouse.ClickAsync(10, 10);14await page.Touchscreen.ClickAsync(10, 10);15await page.Mouse.ClickAsync(10, 10);16await page.Touchscreen.ClickAsync(10, 10);17await page.Mouse.ClickAsync(10, 10

Full Screen

Full Screen

ClickAsync

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using PuppeteerSharp;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.ClickAsync("a[href='/intl/en/about.html']");14 }15 }16 }17}18Related posts: PuppeteerSharp – How to get the size of a page PuppeteerSharp – How to use the WaitForSelectorAsync() method PuppeteerSharp – How to use the WaitForXPathAsync() method PuppeteerSharp – How to use the WaitForRequestAsync() method PuppeteerSharp – How to use the WaitForResponseAsync() method PuppeteerSharp – How to use the WaitForFunctionAsync() method PuppeteerSharp – How to use the WaitForNavigationAsync() method PuppeteerSharp – How to use the WaitForSelectorAsync() method PuppeteerSharp – How to use the WaitForXPathAsync() method PuppeteerSharp – How to use the WaitForRequestAsync() method PuppeteerSharp – How to use the WaitForResponseAsync() method PuppeteerSharp – How to use the WaitForFunctionAsync() method PuppeteerSharp – How to use the WaitForNavigationAsync() method

Full Screen

Full Screen

ClickAsync

Using AI Code Generation

copy

Full Screen

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

Full Screen

Full Screen

ClickAsync

Using AI Code Generation

copy

Full Screen

1var page = await browser.NewPageAsync();2var elementHandle = await page.QuerySelectorAsync("input[name='q']");3await elementHandle.ClickAsync();4var page = await browser.NewPageAsync();5var elementHandle = await page.QuerySelectorAsync("input[name='q']");6await elementHandle.ClickAsync();7var page = await browser.NewPageAsync();8var elementHandle = await page.QuerySelectorAsync("input[name='q']");9await page.ClickAsync("input[name='q']");10var page = await browser.NewPageAsync();11var elementHandle = await page.QuerySelectorAsync("input[name='q']");12await page.MainFrame.ClickAsync("input[name='q']");13var page = await browser.NewPageAsync();14var elementHandle = await page.QuerySelectorAsync("input[name='q']");15await elementHandle.ClickAsync();16var page = await browser.NewPageAsync();17var elementHandle = await page.QuerySelectorAsync("input[name='q']");18await elementHandle.ContentFrame.ClickAsync("input[name='q']");19var page = await browser.NewPageAsync();20var elementHandle = await page.QuerySelectorAsync("input[name='q']");21await elementHandle.ContentFrame.ClickAsync("input[name='q']");22var page = await browser.NewPageAsync();

Full Screen

Full Screen

ClickAsync

Using AI Code Generation

copy

Full Screen

1var mouse = page.Mouse;2await mouse.ClickAsync(10, 10, new ClickOptions { ClickCount = 2 });3var mouse = page.Mouse;4await mouse.ClickAsync(10, 10, new ClickOptions { ClickCount = 2 });5var mouse = page.Mouse;6await mouse.ClickAsync(10, 10, new ClickOptions { ClickCount = 2 });7var mouse = page.Mouse;8await mouse.ClickAsync(10, 10, new ClickOptions { ClickCount = 2 });9var mouse = page.Mouse;10await mouse.ClickAsync(10, 10, new ClickOptions { ClickCount = 2 });11var mouse = page.Mouse;12await mouse.ClickAsync(10, 10, new ClickOptions { ClickCount = 2 });13var mouse = page.Mouse;14await mouse.ClickAsync(10, 10, new ClickOptions { ClickCount = 2 });15var mouse = page.Mouse;16await mouse.ClickAsync(10, 10, new ClickOptions { ClickCount = 2 });17var mouse = page.Mouse;18await mouse.ClickAsync(10, 10, new ClickOptions { ClickCount = 2 });19var mouse = page.Mouse;20await mouse.ClickAsync(10, 10, new ClickOptions { ClickCount = 2 });21var mouse = page.Mouse;22await mouse.ClickAsync(10, 10, new Click

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful