Best Puppeteer-sharp code snippet using PuppeteerSharp.ElementHandle.ClickAsync
Program.cs
Source:Program.cs
...33 {34 LoginManager passwordManager = new LoginManager();35 page.Popup += new EventHandler<PopupEventArgs>(passwordManager.LoginWithGoogle); 36 await page.WaitForSelectorAsync("[data-test=have-account]");37 await page.ClickAsync("div._3uMJF");38 Console.WriteLine("Loading Complete! Please enter your Duolingo login credentials:");39 await passwordManager.LoginToDuolingo(page);40 // Check for "Continue with Google" button141 Thread.Sleep(5000);42 if (await page.QuerySelectorAsync("button._3HhhB._2NolF._275sd._1ZefG._2Dar-._2zhZF") != null) {43 44 // await page.WaitForSelectorAsync("button._3HhhB._2NolF._275sd._1ZefG._2Dar-._2zhZF");45 await page.ClickAsync("button._3HhhB._2NolF._275sd._1ZefG._2Dar-._2zhZF");46 // _3HhhB _2NolF _275sd _1ZefG _2Dar- _2zhZF47 await page.WaitForSelectorAsync("div._3E4oM._3jIW4._3iLdv._2d3xe"); // "Learn" Button: To wait for login to complete before attempting to navigate to story.48 IEnumerable<String> storyList = await GetStoryList();49 Thread.Sleep(5000);50 Page storiesPage = await browser.NewPageAsync();51 await StoryGrind(storiesPage, page, storyList);52 } else {53 await page.WaitForSelectorAsync("div._3E4oM._3jIW4._3iLdv._2d3xe"); // "Learn" Button: To wait for login to complete before attempting to navigate to story.54 IEnumerable<String> storyList = await GetStoryList();55 Thread.Sleep(5000);56 Page storiesPage = await browser.NewPageAsync();57 await StoryGrind(storiesPage, page, storyList);58 }59 }60 61 static async Task StoryGrind(Page storiesPage, Page pageToClose, IEnumerable<String> storyList)62 {63 // await pageToClose.CloseAsync();64 // Navigate to stories page and begin story grinding65 foreach (string url in storyList) {66 string processedURL = ProcessURL(url);67 await storiesPage.GoToAsync(processedURL, new NavigationOptions {Timeout = 0});68 ElementHandle title = await storiesPage.WaitForSelectorAsync("div.saQLX", new WaitForSelectorOptions {Timeout = 0});69 JSHandle titleText = await title.GetPropertyAsync("textContent"); 70 Console.WriteLine("\nBeginning grinding on \"{0}\"", await titleText.JsonValueAsync());71 // await storiesPage.WaitForNavigationAsync();72 ElementHandle startButton = await storiesPage.WaitForSelectorAsync("[data-test=\"story-start\"]");73 await startButton.ClickAsync();74 // Story has been entered/started75 await CompleteStory(storiesPage);76 await ExitStory(storiesPage);77 }78 Console.ReadKey();79 }80 static async Task CompleteStory(Page storiesPage) {81 ElementHandle button = await storiesPage.WaitForSelectorAsync("[data-test=\"stories-player-continue\"]");82 int attempts = 0;83 while (storiesPage.QuerySelectorAsync("[data-test=\"stories-player-continue\"]") != null) {84 ElementHandle continueButton = await storiesPage.WaitForSelectorAsync("[data-test=\"stories-player-continue\"]");85 await continueButton.ClickAsync();86 if (await storiesPage.QuerySelectorAsync("[data-test=\"stories-choice\"]") != null) {87 ElementHandle[] choices = await storiesPage.QuerySelectorAllAsync("[data-test=\"stories-choice\"]");88 foreach (ElementHandle element in choices) {89 await element.ClickAsync();90 } 91 } else if (await storiesPage.QuerySelectorAsync("[data-test=\"challenge-tap-token\"]") != null) {92 ElementHandle[] choices = await storiesPage.QuerySelectorAllAsync("[data-test=\"challenge-tap-token\"]");93 if (choices.Length < 5) {94 foreach (ElementHandle element in choices) {95 await element.ClickAsync();96 } 97 } else {98 ElementHandle[] tokens = await storiesPage.QuerySelectorAllAsync("[data-test=\"challenge-tap-token\"]");99 Random rng = new Random();100 ElementHandle[] disabledTokens = await storiesPage.QuerySelectorAllAsync("[aria-disabled=\"true\"]");101 while (await storiesPage.QuerySelectorAsync("span._3Y29z._176_d._2jNpf") == null || await storiesPage.QuerySelectorAsync("h2._1qFda") != null) {102 103 rng.Shuffle<ElementHandle>(tokens);104 foreach (ElementHandle element in tokens) {105 disabledTokens = await storiesPage.QuerySelectorAllAsync("[aria-disabled=\"true\"]");106 foreach (ElementHandle disabledToken in disabledTokens) {107 int index = Array.IndexOf(tokens, disabledToken);108 tokens.Where(val => val != disabledToken).ToArray();109 }110 await element.ClickAsync();111 Console.Write("\rTook {0} attempt(s) to complete matching tokens.", attempts); 112 attempts++; 113 }114 }115 return;116 }117 } 118 } 119 }120 static async Task ExitStory(Page page) {121 while (await page.QuerySelectorAsync("[data-test=\"stories-player-done\"]") == null) {122 await page.ClickAsync("[data-test=\"stories-player-continue\"]");123 }124 ElementHandle completeButton = await page.WaitForSelectorAsync("[data-test=\"stories-player-done\"]");125 await page.ClickAsync("[data-test=\"stories-player-done\"]");126 await page.WaitForSelectorAsync("div._3wEt9");127 }128 static async Task<IEnumerable<String>> GetStoryList() {129 IEnumerable<String> storyUrls = new string[] {};130 Page page = await browser.NewPageAsync();131 await page.GoToAsync("https://www.duolingo.com/stories", new NavigationOptions {Timeout = 0});132 Thread.Sleep(TimeSpan.FromSeconds(2));133 ElementHandle[] storyIcons = await page.QuerySelectorAllAsync("div.X4jDx");134 foreach (ElementHandle element in storyIcons) {135 await element.ClickAsync();136 ElementHandle startButton = await page.QuerySelectorAsync("[data-test=\"story-start-button\"]");137 if (startButton != null) {138 JSHandle buttonHref = await startButton.GetPropertyAsync("href");139 object hrefJSON = await buttonHref.JsonValueAsync();140 storyUrls = storyUrls.Append<String>(hrefJSON.ToString());141 Console.WriteLine("Appended {0} to list of stories.", await buttonHref.JsonValueAsync());142 } else {143 Console.WriteLine("Skipped a story because it was locked.");144 }145 }146 // await page.CloseAsync();147 return storyUrls;148 }149 static String ProcessURL(String url) {...
ClickTests.cs
Source:ClickTests.cs
...17 public async Task ShouldWork()18 {19 await Page.GoToAsync(TestConstants.ServerUrl + "/input/button.html");20 var button = await Page.QuerySelectorAsync("button");21 await button.ClickAsync();22 Assert.Equal("Clicked", await Page.EvaluateExpressionAsync<string>("result"));23 }24 [PuppeteerTest("elementhandle.spec.ts", "ElementHandle.click", "should work for Shadow DOM v1")]25 [PuppeteerFact]26 public async Task ShouldWorkForShadowDomV1()27 {28 await Page.GoToAsync(TestConstants.ServerUrl + "/shadow.html");29 var buttonHandle = (ElementHandle)await Page.EvaluateExpressionHandleAsync("button");30 await buttonHandle.ClickAsync();31 Assert.True(await Page.EvaluateExpressionAsync<bool>("clicked"));32 }33 [PuppeteerTest("elementhandle.spec.ts", "ElementHandle.click", "should work for TextNodes")]34 [PuppeteerFact]35 public async Task ShouldWorkForTextNodes()36 {37 await Page.GoToAsync(TestConstants.ServerUrl + "/input/button.html");38 var buttonTextNode = (ElementHandle)await Page.EvaluateExpressionHandleAsync(39 "document.querySelector('button').firstChild");40 var exception = await Assert.ThrowsAsync<PuppeteerException>(async () => await buttonTextNode.ClickAsync());41 Assert.Equal("Node is not of type HTMLElement", exception.Message);42 }43 [PuppeteerTest("elementhandle.spec.ts", "ElementHandle.click", "should throw for detached nodes")]44 [PuppeteerFact]45 public async Task ShouldThrowForDetachedNodes()46 {47 await Page.GoToAsync(TestConstants.ServerUrl + "/input/button.html");48 var button = await Page.QuerySelectorAsync("button");49 await Page.EvaluateFunctionAsync("button => button.remove()", button);50 var exception = await Assert.ThrowsAsync<PuppeteerException>(async () => await button.ClickAsync());51 Assert.Equal("Node is detached from document", exception.Message);52 }53 [PuppeteerTest("elementhandle.spec.ts", "ElementHandle.click", "should throw for hidden nodes")]54 [PuppeteerFact]55 public async Task ShouldThrowForHiddenNodes()56 {57 await Page.GoToAsync(TestConstants.ServerUrl + "/input/button.html");58 var button = await Page.QuerySelectorAsync("button");59 await Page.EvaluateFunctionAsync("button => button.style.display = 'none'", button);60 var exception = await Assert.ThrowsAsync<PuppeteerException>(async () => await button.ClickAsync());61 Assert.Equal("Node is either not visible or not an HTMLElement", exception.Message);62 }63 [PuppeteerTest("elementhandle.spec.ts", "ElementHandle.click", "should throw for recursively hidden nodes")]64 [PuppeteerFact]65 public async Task ShouldThrowForRecursivelyHiddenNodes()66 {67 await Page.GoToAsync(TestConstants.ServerUrl + "/input/button.html");68 var button = await Page.QuerySelectorAsync("button");69 await Page.EvaluateFunctionAsync("button => button.parentElement.style.display = 'none'", button);70 var exception = await Assert.ThrowsAsync<PuppeteerException>(async () => await button.ClickAsync());71 Assert.Equal("Node is either not visible or not an HTMLElement", exception.Message);72 }73 [PuppeteerTest("elementhandle.spec.ts", "ElementHandle.click", "should throw for <br> elements")]74 [PuppeteerFact]75 public async Task ShouldThrowForBrElements()76 {77 await Page.SetContentAsync("hello<br>goodbye");78 var br = await Page.QuerySelectorAsync("br");79 var exception = await Assert.ThrowsAsync<PuppeteerException>(async () => await br.ClickAsync());80 Assert.Equal("Node is either not visible or not an HTMLElement", exception.Message);81 }82 }83}...
TravelerPictureBook.cs
Source:TravelerPictureBook.cs
...31 .Where(div => div.EvaluateFunctionAsync<string>("e => e.className").Result.Contains("day-list-item"))32 .ToArray();33 foreach (ElementHandle dayDiv in dayDivs)34 {35 await dayDiv.ClickAsync();36 Thread.Sleep(1000);37 38 ElementHandle[] getDivs = (await _page.QuerySelectorAllAsync("div"))39 .Where(div => div.EvaluateFunctionAsync<string>("e => e.innerHTML").Result == "ÐолÑÑиÑÑ")40 .ToArray();41 42 foreach (ElementHandle getDiv in getDivs)43 {44 await getDiv.ClickAsync();45 Thread.Sleep(1000);46 }47 }48 49 _page.QuerySelectorAsync("div[class^='components-topNav-assets-__topNav_---close-btn---']").Result50 .ClickAsync().GetAwaiter().GetResult();51 Thread.Sleep(3000);52 53 await PptrUtils.WaitAndClick("div.main-button.main-button__right", PptrUtils.LongSelectorAwaiter);54 Thread.Sleep(3000);55 56 (await _page.QuerySelectorAllAsync("div"))57 .FirstOrDefault(div => div.EvaluateFunctionAsync<string>("e => e.innerHTML").Result == "ÐÑмена")58 ?.ClickAsync().GetAwaiter().GetResult();59 Thread.Sleep(1000);60 61 await PptrUtils.WaitAndClick("div.button-spot__progress", PptrUtils.LongSelectorAwaiter);62 Thread.Sleep(3000);63 ElementHandle[] awardIcons = await _page.QuerySelectorAllAsync("div[class^='components-award-assets-__award_---icon---'");64 foreach (ElementHandle awardIcon in awardIcons)65 {66 await awardIcon.ClickAsync();67 Thread.Sleep(1000);68 69 //grab award70 (await _page.QuerySelectorAllAsync("div"))71 .FirstOrDefault(div => div.EvaluateFunctionAsync<string>("e => e.innerHTML").Result == "ÐолÑÑиÑÑ")72 ?.ClickAsync().GetAwaiter().GetResult();73 Thread.Sleep(1000);74 await PptrUtils.ClickIfExists("div[class^='components-result-assets-__result_---click-close---'");75 }76 77 Console.WriteLine("debug");78 }79 catch (Exception e)80 {81 Console.WriteLine(e);82 }83 finally84 {85 await PptrUtils.CloseAsync();86 }...
PuppeteerSharpRepoSpecs.cs
Source:PuppeteerSharpRepoSpecs.cs
...24 Page page = Browser.NewPageAsync().Await();25 page.GoToAsync("https://github.com/").Await();26 page.QuerySelectorAsync("h1").ShouldHaveContent("Where the world builds software");27 ElementHandle input = page.QuerySelectorAsync("input.header-search-input").Await();28 if (input.IsHidden()) page.ClickAsync(".octicon-three-bars").Await();29 page.TypeAsync("input.header-search-input", "Puppeteer Sharp").Await();30 page.Keyboard.PressAsync("Enter").Await();31 page.WaitForNavigationAsync().Await();32 ElementHandle[] repositories = page.QuerySelectorAllAsync(".repo-list-item").Await();33 repositories.Length.ShouldBeGreaterThan(0);34 var repository = repositories.First();35 repository.ShouldHaveContent("hardkoded/puppeteer-sharp");36 ElementHandle text = repository.QuerySelectorAsync("p").Await();37 text.ShouldHaveContent("Headless Chrome .NET API");38 ElementHandle link = repository.QuerySelectorAsync("a").Await();39 link.ClickAsync().Await();40 page.WaitForNavigationAsync().Await();41 page.QuerySelectorAsync("article > h1").ShouldHaveContent("Puppeteer Sharp");42 page.Url.ShouldEqual("https://github.com/hardkoded/puppeteer-sharp");43 };44 }45 class When_viewing_the_repo_on_GitHub46 {47 It should_have_successful_build_status = () =>48 {49 Page page = Browser.NewPageAsync().Await();50 page.GoToAsync("https://github.com/hardkoded/puppeteer-sharp").Await();51 ElementHandle build = page.QuerySelectorAsync("img[alt='Build status']").Await();52 build.ClickAsync().Await();53 page.WaitForNavigationAsync(new NavigationOptions { WaitUntil = new[] { WaitUntilNavigation.Networkidle0 } }).Await();54 ElementHandle success = page.QuerySelectorAsync(".project-build.project-build-status.success").Await();55 success.ShouldExist();56 };57 It should_be_up_to_date_with_the_Puppeteer_version = () =>58 {59 Page page = Browser.NewPageAsync().Await();60 page.GoToAsync("https://github.com/hardkoded/puppeteer-sharp").Await();61 var puppeteerSharpVersion = GetLatestReleaseVersion();62 page.GoToAsync("https://github.com/puppeteer/puppeteer").Await();63 var puppeteerVersion = GetLatestReleaseVersion();64 puppeteerSharpVersion.ShouldEqual(puppeteerVersion);65 string GetLatestReleaseVersion()66 {...
GoogleWebToolKit.cs
Source:GoogleWebToolKit.cs
...30 }31 else32 xPath = "//input [@id='gwt-debug-cwCheckBox-Wednesday-input']";33 ElementHandle element = await page.WaitForXPathAsync(xPath);34 await element.ClickAsync();35 }36 [Then(@"zeitschleife")]37 public async Task ThenZeitschleife()38 {39 Thread.Sleep(200);40 }41 [Then(@"Flex Table: ""(.*)""")]42 public async Task ThenFlexTable(string befehl)43 {44 string xPath = "";45 if (befehl.Contains("Add a row"))46 {47 xPath = "//button[contains(text(),'Add a row')]";48 } else49 {50 xPath = "//button[contains(text(),'Remove a row')]";51 }52 ElementHandle element = await page.WaitForXPathAsync(xPath);53 await element.ClickAsync();54 Thread.Sleep(1000);55 }56 [Then(@"Set favorit-sport RB to: ""(.*)""")]57 public async Task ThenSetFavorit_SportRBTo(string faforitSport)58 {59 string xPath = "//input [@id='gwt-debug-cwRadioButton-sport-Hockey-input']";60 ElementHandle element = await page.WaitForXPathAsync(xPath);61 await element.ClickAsync();62 Thread.Sleep(1000);63 }64 65 [Then(@"click-button mit Text: '(.*)'")]66 public async Task ThenClick_ButtonMitText(string erwarteterText)67 {68 ElementHandle[] elements = await webPage.WarteForSelector("button", erwarteterText, 15);69 bool gefunden = false;70 71 if (elements != null)72 {73 foreach (var element in elements)74 {75 var textId = (await page.EvaluateFunctionAsync<string>("e => e.innerText", element));76 string innerText = (await page.EvaluateFunctionAsync<string>("e => e.innerText", element));77 _NLogger.Info("textId=" + textId + " **** innerTex=" + innerText);78 if (innerText == erwarteterText)79 {80 gefunden = true;81 await element.ClickAsync();82 break;83 }84 }85 }86 Thread.Sleep(2000);87 }88 }89}...
pay.cshtml.cs
Source:pay.cshtml.cs
...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}...
IPuppeteerBrowser.cs
Source:IPuppeteerBrowser.cs
...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>...
PageObjects.cs
Source:PageObjects.cs
...17 public virtual Task<ElementHandle> SearchInput { get; }18 public async Task<GitHubSearchPage> Search(string text)19 {20 var input = await SearchInput;21 if (await input.IsHiddenAsync()) await Page.ClickAsync(".octicon-three-bars");22 await input.TypeAsync(text);23 await input.PressAsync(Key.Enter);24 return await Page.WaitForNavigationAsync<GitHubSearchPage>();25 }26 }27 public class GitHubSearchPage : PageObject28 {29 [Selector(".repo-list-item")]30 public virtual Task<GitHubRepoListItem[]> RepoListItems { get; }31 }32 public class GitHubRepoListItem : ElementObject33 {34 [Selector("a")]35 public virtual Task<ElementHandle> Link { get; }...
ClickAsync
Using AI Code Generation
1await page.ClickAsync("a");2await page.ClickAsync("a");3await page.ClickAsync("a");4await page.ClickAsync("a");5await page.ClickAsync("a");6await page.ClickAsync("a");7await page.ClickAsync("a");8await page.ClickAsync("a");9await page.ClickAsync("a");10await page.ClickAsync("a");11await page.ClickAsync("a");12await page.ClickAsync("a");13await page.ClickAsync("a");14await page.ClickAsync("a");15await page.ClickAsync("a");16await page.ClickAsync("a");17await page.ClickAsync("a");18await page.ClickAsync("a");19await page.ClickAsync("a");20await page.ClickAsync("a");21await page.ClickAsync("a");
ClickAsync
Using AI Code Generation
1var page = await browser.NewPageAsync();2var searchBox = await page.QuerySelectorAsync("input[name=q]");3await searchBox.ClickAsync();4await searchBox.TypeAsync("PuppeteerSharp");5await page.Keyboard.PressAsync("Enter");6await page.WaitForNavigationAsync();7var results = await page.QuerySelectorAllAsync("h3");8foreach (var result in results)9{10 Console.WriteLine(await result.EvaluateFunctionAsync<string>("node => node.innerText"));11}12var page = await browser.NewPageAsync();13var searchBox = await page.QuerySelectorAsync("input[name=q]");14await searchBox.ClickAsync();15await searchBox.TypeAsync("PuppeteerSharp");16await page.Keyboard.PressAsync("Enter");17await page.WaitForNavigationAsync();18var results = await page.QuerySelectorAllAsync("h3");19foreach (var result in results)20{21 Console.WriteLine(await result.EvaluateFunctionAsync<string>("node => node.innerText"));22}23var page = await browser.NewPageAsync();24var searchBox = await page.QuerySelectorAsync("input[name=q]");25await searchBox.ClickAsync();26await searchBox.TypeAsync("PuppeteerSharp");27await page.Keyboard.PressAsync("Enter");28await page.WaitForNavigationAsync();29var results = await page.QuerySelectorAllAsync("h3");30foreach (var result in results)31{32 Console.WriteLine(await result.EvaluateFunctionAsync<string>("node => node.innerText"));33}34var page = await browser.NewPageAsync();35var searchBox = await page.QuerySelectorAsync("input[name=q]");36await searchBox.ClickAsync();37await searchBox.TypeAsync("PuppeteerSharp");38await page.Keyboard.PressAsync("Enter");39await page.WaitForNavigationAsync();40var results = await page.QuerySelectorAllAsync("h3");41foreach (var result in results)42{43 Console.WriteLine(await result.EvaluateFunctionAsync<string>("node => node.innerText"));44}
ClickAsync
Using AI Code Generation
1var element = await page.QuerySelectorAsync("button");2await element.ClickAsync();3await page.ClickAsync("button");4await page.ClickAsync("button", new ClickOptions {Delay = 1000});5await page.ClickAsync("button", new ClickOptions {Button = MouseButton.Right});6await page.ClickAsync("button", new ClickOptions {ClickCount = 2});7await page.ClickAsync("button", new ClickOptions {Modifiers = new [] { KeyModifier.Control, KeyModifier.Alt }});8var element = await page.QuerySelectorAsync("button");9await element.ClickAsync();10await page.ClickAsync("button");11await page.ClickAsync("button", new ClickOptions {Delay = 1000});12await page.ClickAsync("button", new ClickOptions {Button = MouseButton.Right});13await page.ClickAsync("button", new ClickOptions {ClickCount = 2});14await page.ClickAsync("button", new ClickOptions {Modifiers = new [] { KeyModifier.Control, KeyModifier.Alt }});15var element = await page.QuerySelectorAsync("button");16await element.ClickAsync();17await page.ClickAsync("button");18await page.ClickAsync("button", new ClickOptions {Delay = 1000});19await page.ClickAsync("button", new ClickOptions {Button = MouseButton.Right});
ClickAsync
Using AI Code Generation
1var page = await browser.NewPageAsync();2var search = await page.QuerySelectorAsync("input[name='q']");3await search.ClickAsync();4await page.Keyboard.TypeAsync("PuppeteerSharp");5await page.Keyboard.PressAsync("Enter");6await page.ScreenshotAsync("1.png");7var page = await browser.NewPageAsync();8var search = await page.QuerySelectorAsync("input[name='q']");9await page.ClickAsync("input[name='q']");10await page.Keyboard.TypeAsync("PuppeteerSharp");11await page.Keyboard.PressAsync("Enter");12await page.ScreenshotAsync("2.png");13var page = await browser.NewPageAsync();14var search = await page.QuerySelectorAsync("input[name='q']");15await page.MainFrame.ClickAsync("input[name='q']");16await page.Keyboard.TypeAsync("PuppeteerSharp");17await page.Keyboard.PressAsync("Enter");18await page.ScreenshotAsync("3.png");19var page = await browser.NewPageAsync();20var search = await page.QuerySelectorAsync("input[name='q']");21await search.ClickAsync();22await page.Keyboard.TypeAsync("PuppeteerSharp");23await page.Keyboard.PressAsync("Enter");24await page.ScreenshotAsync("4.png");25var page = await browser.NewPageAsync();26var search = await page.QuerySelectorAsync("input[name='q']");27await page.ClickAsync("input[name='q']");28await page.Keyboard.TypeAsync("PuppeteerSharp");29await page.Keyboard.PressAsync("Enter");30await page.ScreenshotAsync("5.png");31var page = await browser.NewPageAsync();
ClickAsync
Using AI Code Generation
1var page = await browser.NewPageAsync();2var searchBox = await page.QuerySelectorAsync("input[name=q]");3await searchBox.TypeAsync("Puppeteer Sharp");4await searchBox.ClickAsync();5await page.ScreenshotAsync("google.png");6await browser.CloseAsync();7var page = await browser.NewPageAsync();8var searchBox = await page.QuerySelectorAsync("input[name=q]");9await searchBox.TypeAsync("Puppeteer Sharp");10await page.ClickAsync("input[name=q]");11await page.ScreenshotAsync("google.png");12await browser.CloseAsync();
ClickAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {8 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);9 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }))10 using (var page = await browser.NewPageAsync())11 {12 await page.ClickAsync("input[name='btnK']");13 }14 }15 }16}17using System;18using System.Threading.Tasks;19using PuppeteerSharp;20{21 {22 static async Task Main(string[] args)23 {24 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);25 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }))26 using (var page = await browser.NewPageAsync())27 {28 await page.ClickAsync("input[name='btnK']");29 }30 }31 }32}33using System;34using System.Threading.Tasks;35using PuppeteerSharp;36{37 {38 static async Task Main(string[] args)39 {40 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);41 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }))42 using (var page = await browser.NewPageAsync())43 {44 await page.ClickAsync("input[name='btnK']");45 }46 }47 }48}49using System;50using System.Threading.Tasks;51using PuppeteerSharp;52{53 {54 static async Task Main(string[] args)55 {
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!!