How to use ClickAsync method of PuppeteerSharp.Frame class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Frame.ClickAsync

Robot.cs

Source:Robot.cs Github

copy

Full Screen

...85 OnMessage("登录");86 _ = await page.GoToAsync("https://i.qq.com");87 88 var loginFrame = await page.WaitForFrameAsync("login_frame");89 await (await loginFrame.WaitForSelectorAsync("#switcher_plogin")).ClickAsync();90 await (await loginFrame.WaitForSelectorAsync("#u")).TypeAsync(Account.Username);91 await (await loginFrame.WaitForSelectorAsync("#p")).TypeAsync(Account.Password);92 await (await loginFrame.WaitForSelectorAsync("#login_button")).ClickAsync();93 _ = await page.WaitForNavigationAsync();94 }95 private async Task UploadImage()96 {97 OnMessage("点击相册");98 await (await page.WaitForSelectorAsync("a[title=\"相册\"]")).ClickAsync();99 var tphotoFrame = await page.WaitForFrameAsync("tphoto", "app_canvas_frame");100 OnMessage("打开上传对话框");101 await (await tphotoFrame.WaitForSelectorAsync(".j-uploadentry-photo")).ClickAsync();102 var uploadFrame = await page.WaitForFrameAsync("photoUploadDialog");103 await Delay();104 var imagePath = MainViewModel.RandomImage;105 OnMessage($"选择随机文件 {imagePath}");106 var fileChooserTask = page.WaitForFileChooserAsync();107 await Task.WhenAll(fileChooserTask, uploadFrame.ClickAsync(".btn-select-img"));108 await fileChooserTask.Result.AcceptAsync(imagePath.Replace(@"\", @"\\"));109 OnMessage("上传文件");110 await (await uploadFrame.WaitForSelectorAsync(".op-btn.btn-upload")).ClickAsync();111 _ = await page.WaitForSelectorAsync("#photoUploadDialog", new WaitForSelectorOptions() { Hidden = true });112 _ = await tphotoFrame.WaitForSelectorAsync("#desc_all");113 await Delay();114 OnMessage("填写随机文本");115 await tphotoFrame.TypeAsync("#desc_all", MainViewModel.RandomText);116 await Delay();117 await (await tphotoFrame.WaitForSelectorAsync("#back_btn_md")).ClickAsync();118 _ = await tphotoFrame.WaitForNavigationAsync();119 }120 private Task Delay()121 {122 var sec = (int)MainViewModel.DelaySec;123 var ms = sec * 1000;124 OnMessage($"延时{sec}s");125 return Task.Delay(ms);126 }127 }128}...

Full Screen

Full Screen

汽车之家.cs

Source:汽车之家.cs Github

copy

Full Screen

...35 int n = 0;36 while (n++ < 29)37 {38 CreateModelWithAngleSharp(await page.GetContentAsync(), result);39 await page.ClickAsync("#topPager > div > a.page-item-next");40 }41 CarFamilyDatas.IntrusiveExport(result);42 //var replaylist = await page.SelectAsync("#reply-list");43 44 //// await ifrmElement.ClickAsync();45 //var ifrmElement1 = await page.XPathAsync("//*[@id=\"reply-item-72217813\"]");46 //await ifrmElement1[0].ClickAsync();47 //await page.ClickAsync("body > div:nth-child(24) > ul > li:nth-child(5)");48 //var beginDate = await page.SelectAsync("#beginDate");49 //await page.ClickAsync("#beginDate");50 //await page.SelectAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #beginDate");51 //await page.ClickAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #beginDate");52 //await page.SelectAsync(".ui-calendar:nth-child(39) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column > .focused-element");53 //await page.ClickAsync(".ui-calendar:nth-child(39) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column > .focused-element");54 //await page.SelectAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #endDate");55 //await page.ClickAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #endDate");56 //await page.SelectAsync(".ui-calendar:nth-child(40) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column:nth-child(5) > .ui-calendar-day-0");57 //await page.ClickAsync(".ui-calendar:nth-child(40) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column:nth-child(5) > .ui-calendar-day-0");58 //await page.SelectAsync("#main > div.amount-top > div > div.fn-clear.action-other.action-other-show > div.fn-left > div > a.J-download-tip.mr-10");59 //await page.ClickAsync("#main > div.amount-top > div > div.fn-clear.action-other.action-other-show > div.fn-left > div > a.J-download-tip.mr-10");60 ////Get and return the HTML content of the page61 //var htmlString = await page.GetContentAsync();62 }63 private static void CreateModelWithAngleSharp(string html, List<CarFamilyDatas> result)64 {65 var config = Configuration.Default;66 var context = BrowsingContext.New(config);67 var parser = context.GetService<IHtmlParser>();68 var source = html;69 var node = parser.ParseDocument(source);70 var list=node.QuerySelector("#reply-list");71 var content =list.TextContent.Replace("举报", "").Replace("查看对话","").Replace(" +1顶","");72 var lines= content.Split("回复");73 foreach (var line in lines)...

Full Screen

Full Screen

RunChoutiCraper.cs

Source:RunChoutiCraper.cs Github

copy

Full Screen

...35 int n = 0;36 while (n++ < 29)37 {38 CreateModelWithAngleSharp(await page.GetContentAsync(), result);39 await page.ClickAsync("#topPager > div > a.page-item-next");40 }41 CarFamilyDatas.IntrusiveExport(result);42 //var replaylist = await page.SelectAsync("#reply-list");43 //// await ifrmElement.ClickAsync();44 //var ifrmElement1 = await page.XPathAsync("//*[@id=\"reply-item-72217813\"]");45 //await ifrmElement1[0].ClickAsync();46 //await page.ClickAsync("body > div:nth-child(24) > ul > li:nth-child(5)");47 //var beginDate = await page.SelectAsync("#beginDate");48 //await page.ClickAsync("#beginDate");49 //await page.SelectAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #beginDate");50 //await page.ClickAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #beginDate");51 //await page.SelectAsync(".ui-calendar:nth-child(39) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column > .focused-element");52 //await page.ClickAsync(".ui-calendar:nth-child(39) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column > .focused-element");53 //await page.SelectAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #endDate");54 //await page.ClickAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #endDate");55 //await page.SelectAsync(".ui-calendar:nth-child(40) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column:nth-child(5) > .ui-calendar-day-0");56 //await page.ClickAsync(".ui-calendar:nth-child(40) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column:nth-child(5) > .ui-calendar-day-0");57 //await page.SelectAsync("#main > div.amount-top > div > div.fn-clear.action-other.action-other-show > div.fn-left > div > a.J-download-tip.mr-10");58 //await page.ClickAsync("#main > div.amount-top > div > div.fn-clear.action-other.action-other-show > div.fn-left > div > a.J-download-tip.mr-10");59 ////Get and return the HTML content of the page60 //var htmlString = await page.GetContentAsync();61 }62 private static void CreateModelWithAngleSharp(string html, List<CarFamilyDatas> result)63 {64 var config = Configuration.Default;65 var context = BrowsingContext.New(config);66 var parser = context.GetService<IHtmlParser>();67 var source = html;68 var node = parser.ParseDocument(source);69 var list = node.QuerySelector("#reply-list");70 var content = list.TextContent.Replace("举报", "").Replace("查看对话", "").Replace(" +1顶", "");71 var lines = content.Split("回复");72 foreach (var line in lines)...

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

zhifubao.cs

Source:zhifubao.cs Github

copy

Full Screen

...26 // ifrmElement.27 //var ifrmFrame = await ifrmElement.ContentFrameAsync();28 //var ifrmHtml = await ifrmFrame.GetContentAsync();29 // var test = await page.SelectAsync("#J-datetime-select > a:nth-child(3)");30 await page.ClickAsync("#J-datetime-select > a:nth-child(3)");31 await page.ClickAsync("body > div:nth-child(19) > ul > li:nth-child(5)");32 // await ifrmElement.ClickAsync();33 var ifrmElement1 = await page.XPathAsync("/html/body/div[10]/ul/li[5]");34 await ifrmElement1[0].ClickAsync();35 await page.ClickAsync("body > div:nth-child(24) > ul > li:nth-child(5)");36 var beginDate = await page.SelectAsync("#beginDate");37 await page.ClickAsync("#beginDate");38 await page.SelectAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #beginDate");39 await page.ClickAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #beginDate");40 await page.SelectAsync(".ui-calendar:nth-child(39) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column > .focused-element");41 await page.ClickAsync(".ui-calendar:nth-child(39) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column > .focused-element");42 await page.SelectAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #endDate");43 await page.ClickAsync(".record-search-option-date > #J-search-date-container > #J-datetime-select #endDate");44 await page.SelectAsync(".ui-calendar:nth-child(40) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column:nth-child(5) > .ui-calendar-day-0");45 await page.ClickAsync(".ui-calendar:nth-child(40) > .ui-calendar > .ui-calendar-data-container > .ui-calendar-date-column:nth-child(5) > .ui-calendar-day-0");46 await page.SelectAsync("#main > div.amount-top > div > div.fn-clear.action-other.action-other-show > div.fn-left > div > a.J-download-tip.mr-10");47 await page.ClickAsync("#main > div.amount-top > div > div.fn-clear.action-other.action-other-show > div.fn-left > div > a.J-download-tip.mr-10");48 //Get and return the HTML content of the page49 var htmlString = await page.GetContentAsync();50 }51 }52}...

Full Screen

Full Screen

Clean163Email.cs

Source:Clean163Email.cs Github

copy

Full Screen

...23 var user = await frame.WaitForSelectorAsync("input[data-placeholder='邮箱帐号或手机号码']");24 await user.TypeAsync("");25 var password = await frame.WaitForSelectorAsync("input[data-placeholder='输入密码']");26 await password.TypeAsync("");27 await frame.ClickAsync("#dologin");28 var element = await page.WaitForXPathAsync("//*[a='清理邮箱']");29 var cleanBtn = await element.XPathAsync("a[1]");30 await cleanBtn[0].ClickAsync();31 await Task.Delay(3000);32 var frame2 = page.Frames.First(s => s.Name.Contains("frmoutlink"));33 34 await frame2.ClickAsync("#clearTypeDate");35 36 await frame2.ClickAsync("#dateCleanCustom");37 38 await frame2.TypeAsync("#customYearStartIpt", "1990");39 await frame2.TypeAsync("#customMonthStartIpt", "1");40 await frame2.TypeAsync("#customDayStartIpt", "1");41 await frame2.TypeAsync("#customYearEndIpt", "2021");42 await frame2.TypeAsync("#customMonthEndIpt", "2");43 await frame2.TypeAsync("#customDayEndIpt", "18");44 var wait = new WaitForSelectorOptions {Timeout = 5000};45 for (int i = 0; i < 100000; i++)46 {47 try48 {49 var b1 = await frame2.WaitForXPathAsync("//*/div[span='开始扫描']", wait);50 await b1.ClickAsync();51 await Task.Delay(5000);52 var deleteBtn = await frame2.WaitForXPathAsync("//div[span='彻底删除']", wait);53 await deleteBtn.ClickAsync();54 var confirmBtn = await page.WaitForXPathAsync("//div[span='确 定']", wait);55 await confirmBtn.ClickAsync();56 await Task.Delay(4000);57 var confirm2Btn = await page.WaitForXPathAsync("//div[span='确 定']", wait);58 await confirm2Btn.ClickAsync();59 }60 catch (Exception e)61 {62 Console.WriteLine(e);63 }64 }65 }66 }67 }68}...

Full Screen

Full Screen

AuthIntegrationTests.cs

Source:AuthIntegrationTests.cs Github

copy

Full Screen

...42 await passwordField.TypeAsync(Password);43 var confirmPasswordField = await page.MainFrame.QuerySelectorAsync("#ConfirmPassword");44 await confirmPasswordField.TypeAsync(Password);45 var submitButton = await page.MainFrame.QuerySelectorAsync("input[type=submit]");46 await submitButton.ClickAsync();47 await page.MainFrame.WaitForNavigationAsync();48 }49 {50 using var scope = app.Services.CreateScope();51 var dbContext = scope.ServiceProvider.GetRequiredService<DatabaseContext>();52 var query = from user in dbContext.Users.AsQueryable() where user.Email == Email select user;53 var exists = await query.AnyAsync();54 exists.Should().Be(true);55 }56 {57 var cookies = await page.GetCookiesAsync();58 await page.DeleteCookieAsync(cookies);59 await page.GoToAsync($"{app.RootUri}login", waitUntil: WaitUntilNavigation.DOMContentLoaded);60 }61 {62 var emailField = await page.MainFrame.QuerySelectorAsync("#Email");63 await emailField.TypeAsync(Email);64 var passwordField = await page.MainFrame.QuerySelectorAsync("#Password");65 await passwordField.TypeAsync(Password);66 var submitButton = await page.MainFrame.QuerySelectorAsync("input[type=submit]");67 await submitButton.ClickAsync();68 await page.MainFrame.WaitForNavigationAsync();69 var url = new Uri(page.Url);70 url.AbsolutePath.Should().Be("/");71 }72 }73 }74}...

Full Screen

Full Screen

PuppeteerExtensions.cs

Source:PuppeteerExtensions.cs Github

copy

Full Screen

...18 public static async Task TypeAsync(this Frame frame, string selector, string text)19 {20 await (await frame.QuerySelectorAsync(selector)).TypeAsync(text);21 }22 public static async Task ClickAsync(this Frame frame, string selector)23 {24 await (await frame.QuerySelectorAsync(selector)).ClickAsync();25 }26 public static async Task WaitForTruth(this Page page, string script, WaitForFunctionOptions opts = null)27 {28 var jsHandle = await page.WaitForExpressionAsync(script, opts);29 await jsHandle.DisposeAsync();30 }31 public static async Task WaitForDocumentInteractiveState(this Page page, int? timeout = null)32 {33 await page.WaitForTruth("document.readyState === 'interactive' || document.readyState === 'complete'", new WaitForFunctionOptions { Timeout = timeout ?? page.Browser.DefaultWaitForTimeout });34 }35 }36}...

Full Screen

Full Screen

ClickAsync

Using AI Code Generation

copy

Full Screen

1var puppeteer = new PuppeteerSharp.Puppeteer();2var browser = await puppeteer.LaunchAsync(new LaunchOptions { Headless = false });3var page = await browser.NewPageAsync();4await page.ClickAsync("input[name='q']");5await page.Keyboard.TypeAsync("puppeteer-sharp");6var puppeteer = new PuppeteerSharp.Puppeteer();7var browser = await puppeteer.LaunchAsync(new LaunchOptions { Headless = false });8var page = await browser.NewPageAsync();9await page.ClickAsync("input[name='q']");10await page.Keyboard.TypeAsync("puppeteer-sharp");11var puppeteer = new PuppeteerSharp.Puppeteer();12var browser = await puppeteer.LaunchAsync(new LaunchOptions { Headless = false });13var page = await browser.NewPageAsync();14await page.ClickAsync("input[name='q']");15await page.Keyboard.TypeAsync("puppeteer-sharp");16var puppeteer = new PuppeteerSharp.Puppeteer();17var browser = await puppeteer.LaunchAsync(new LaunchOptions { Headless = false });18var page = await browser.NewPageAsync();19await page.ClickAsync("input[name='q']");20await page.Keyboard.TypeAsync("puppeteer-sharp");21var puppeteer = new PuppeteerSharp.Puppeteer();22var browser = await puppeteer.LaunchAsync(new LaunchOptions { Headless = false });23var page = await browser.NewPageAsync();24await page.ClickAsync("input[name='q']");25await page.Keyboard.TypeAsync("puppeteer-sharp");26var puppeteer = new PuppeteerSharp.Puppeteer();27var browser = await puppeteer.LaunchAsync(new LaunchOptions { Head

Full Screen

Full Screen

ClickAsync

Using AI Code Generation

copy

Full Screen

1var browser = await Puppeteer.LaunchAsync(new LaunchOptions2{3});4var page = await browser.NewPageAsync();5await page.ClickAsync("#gb > div > div.gb_Bf.gb_Ag.gb_Fg > div.gb_5.gb_6.gb_7.gb_8.gb_9 > a");6await page.WaitForSelectorAsync("#gb_71");7await page.ClickAsync("#gb_71");8await browser.CloseAsync();9var browser = await Puppeteer.LaunchAsync(new LaunchOptions10{11});12var page = await browser.NewPageAsync();13var searchButton = await page.QuerySelectorAsync("#gb > div > div.gb_Bf.gb_Ag.gb_Fg > div.gb_5.gb_6.gb_7.gb_8.gb_9 > a");14await searchButton.ClickAsync();15var signOutButton = await page.QuerySelectorAsync("#gb_71");16await signOutButton.ClickAsync();17await browser.CloseAsync();18var browser = await Puppeteer.LaunchAsync(new LaunchOptions19{20});21var page = await browser.NewPageAsync();22await page.ClickAsync("#gb > div > div.gb_Bf.gb_Ag.gb_Fg > div.gb_5.gb_6.gb_7.gb_8.gb_9 > a");23await page.WaitForSelectorAsync("#gb_71");24await page.ClickAsync("#gb_71");25await browser.CloseAsync();26var browser = await Puppeteer.LaunchAsync(new LaunchOptions27{28});29var page = await browser.NewPageAsync();30await page.ClickAsync("#gb > div > div.gb_Bf.gb_Ag.gb_Fg > div.gb_5.gb_6.gb_7.gb

Full Screen

Full Screen

ClickAsync

Using AI Code Generation

copy

Full Screen

1var browser = await Puppeteer.LaunchAsync(new LaunchOptions2{3 ExecutablePath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",4 Args = new string[] { "--start-maximized" }5});6var page = await browser.NewPageAsync();7await page.ClickAsync("input[name='q']");8await page.Keyboard.TypeAsync("PuppeteerSharp");9await page.Keyboard.PressAsync("Enter");10await page.WaitForNavigationAsync();11await page.ScreenshotAsync("puppeteer-sharp.png");

Full Screen

Full Screen

ClickAsync

Using AI Code Generation

copy

Full Screen

1var page = await browser.NewPageAsync();2await page.ClickAsync("input[name=q]");3await page.TypeAsync("PuppeteerSharp");4await page.ClickAsync("input[value='Google Search']");5var page = await browser.NewPageAsync();6var input = await page.QuerySelectorAsync("input[name=q]");7await input.ClickAsync();8await page.TypeAsync("PuppeteerSharp");9await page.ClickAsync("input[value='Google Search']");10var page = await browser.NewPageAsync();11await page.ClickAsync("input[name=q]");12await page.TypeAsync("PuppeteerSharp");13await page.ClickAsync("input[value='Google Search']");14var page = await browser.NewPageAsync();15await page.ClickAsync("input[name=q]");16await page.TypeAsync("PuppeteerSharp");17await page.ClickAsync("input[value='Google Search']");18var page = await browser.NewPageAsync();19var input = await page.QuerySelectorAsync("input[name=q]");20await input.ClickAsync();21await page.TypeAsync("PuppeteerSharp");22await page.ClickAsync("input[value='Google Search']");23var page = await browser.NewPageAsync();24await page.ClickAsync("input[name=q]");25await page.TypeAsync("PuppeteerSharp");26await page.ClickAsync("input[value='Google Search']");27var page = await browser.NewPageAsync();28await page.ClickAsync("input[name=q]");29await page.TypeAsync("PuppeteerSharp");

Full Screen

Full Screen

ClickAsync

Using AI Code Generation

copy

Full Screen

1string[] lines = File.ReadAllLines("1.cs");2string[] newLines = Regex.Replace(lines, "PuppeteerSharp.Frame", "Frame");3WebElement element = driver.findElement(By.id("myID"));4String value = element.getAttribute("value");5WebElement element = driver.findElement(By.id("myID"));6String value = element.getText();7WebElement element = driver.findElement(By.id("myID"));8String value = element.getAttribute("innerHTML");9WebElement element = driver.findElement(By.id("myID"));10String value = element.getAttribute("innerText");11WebElement element = driver.findElement(By.id("myID"));12String value = element.getAttribute("textContent");13WebElement element = driver.findElement(By.id("myID"));14String value = element.getAttribute("outerHTML");15WebElement element = driver.findElement(By.id("myID"));16String value = element.getAttribute("outerText");17WebElement element = driver.findElement(By.id("myID"));18String value = element.getAttribute("text");

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful