Best Puppeteer-sharp code snippet using PuppeteerSharp.ElementHandle.QuerySelectorAsync
VkBrwUserFactory.cs
Source:VkBrwUserFactory.cs
...136 return nwPages;137 }138 private async Task<VkBrwCommunity> GetCommunityAsync(ElementHandle communityElement, BrowserContext userContext)139 {140 ElementHandle communityNameElement = await communityElement.QuerySelectorAsync("div.fans_idol_name");141 if (communityNameElement != null)142 {143 VkBrwCommunity nwPage = new VkBrwCommunity();144 ////await page.EvaluateFunctionAsync(@"() => {145 //// Array.from(document.querySelectorAll('li'))146 //// .find(l => l.querySelector('span').innerText === 'fire').querySelector('INPUT').click();147 ////}");148 // equals to $eval('a', a => a.innerText)149 nwPage.Name = await communityNameElement.EvaluateFunctionAsync<string>("('a', a => a.innerText)");150 ElementHandle communityLinkElement = await communityElement.QuerySelectorAsync("a.fans_idol_lnk");151 nwPage.CommunityUrl = await communityLinkElement.EvaluateFunctionAsync<string>("('a', a => a.href)");152 ElementHandle communityStatusElement = await communityElement.QuerySelectorAsync("div.fans_idol_status");153 nwPage.Status = await communityStatusElement.EvaluateFunctionAsync<string>("('div', div => div.innerText)");154 ElementHandle communitySizeElement = await communityElement.QuerySelectorAsync("div.fans_idol_size");155 nwPage.Size = await communitySizeElement.EvaluateFunctionAsync<string>("('div', div => div.innerText)");156 if (!nwPage.CommunityUrl.Contains("event"))157 {158 await GetCommunityDetailsAsync(userContext, nwPage);159 }160 return nwPage;161 }162 else163 {164 return null;165 }166 }167 private async Task GetCommunityDetailsAsync(BrowserContext browserContext, VkBrwCommunity community)168 {169 Page communityPage = await browserContext.NewPageAsync();170 ////groupPage.EvaluateFunctionAsync($"() => window.open('{groupUrl}')").GetAwaiter().GetResult();171 ////Target newWindowTarget = browser.WaitForTargetAsync(target => target.Url == "https://www.example.com/").Result;172 ////Page newPage = newWindowTarget.PageAsync().Result;173 try174 {175 await communityPage.GoToAsync(community.CommunityUrl);176 }177 catch (NavigationException)178 {179 return;180 }181 WaitForSelectorOptions waitSelectorOptions = new WaitForSelectorOptions { Timeout = 10000 };182 ElementHandle communityLoadedElement = await communityPage.WaitForSelectorAsync("div#page_wrap.scroll_fix_wrap._page_wrap", waitSelectorOptions);183 if (communityLoadedElement != null)184 {185 ElementHandle communityBlockedElement = await communityPage.QuerySelectorAsync("div.groups_blocked");186 if (communityBlockedElement != null)187 {188 community.Blocked = true;189 }190 else191 {192 community.Type = await GetCommunityTypeAsync(communityPage);193 community.CommunityId = await GetCommunityIdAsync(communityPage, community.Type);194 }195 }196 await communityPage.CloseAsync();197 }198 private async Task<CommunityTypes> GetCommunityTypeAsync(Page communityPage)199 {200 ElementHandle publicElement = await communityPage.QuerySelectorAsync("#public_followers.module.clear.people_module._module");201 if (publicElement!= null)202 {203 return CommunityTypes.Public;204 }205 ElementHandle groupElement = await communityPage.QuerySelectorAsync("#group_followers.module.clear.people_module._module");206 if (groupElement != null)207 {208 return CommunityTypes.Group;209 }210 if (communityPage.Url.Contains("event"))211 {212 return CommunityTypes.Event;213 }214 return CommunityTypes.Unknown;215 }216 private async Task<string> GetCommunityIdAsync(Page communityPage, CommunityTypes type)217 {218 string result = null;219 string linkString = (type == CommunityTypes.Public) ?220 "#public_followers.module.clear.people_module._module" : "#group_followers.module.clear.people_module._module";221 ElementHandle communityFollowersElement = await communityPage.QuerySelectorAsync(linkString);222 223 if (communityFollowersElement != null)224 {225 ElementHandle communityFollowersSearchElement = await communityFollowersElement.QuerySelectorAsync("a.module_header");226 string communityFollowersSearchLink = await communityFollowersSearchElement.EvaluateFunctionAsync<string>("('a', a => a.href)");227 string linkLastPart = communityFollowersSearchLink.Split("=").Last();228 if (!string.IsNullOrEmpty(linkLastPart))229 {230 result = linkLastPart;231 }232 }233 else234 {235 bool isPersonalPage = await IsPersonalPage(communityPage);236 if (isPersonalPage)237 {238 //ÑоздаÑÑ Ð¿Ð¾Ð»ÑзоваÑелÑ239 }240 }241 return result;242 }243 private async Task<bool> IsPersonalPage(Page page)244 {245 ElementHandle pageFollowersSearchElement = await page.QuerySelectorAsync("#profile.profile_content");246 return pageFollowersSearchElement != null;247 }248 }249}...
Scraping.cs
Source:Scraping.cs
...24 var linkList = await page.QuerySelectorAllAsync("div.card a");25 foreach(var link in linkList)26 {27 var url = await (await link.GetPropertyAsync("href")).JsonValueAsync<string>();28 var title = await(await(await link.QuerySelectorAsync("h4")).GetPropertyAsync("innerText")).JsonValueAsync<string>();29 Console.WriteLine($"Found area: {title}");30 result.Add((url: url, title: title));31 }32 return result;33 }34 public static async Task<List<TaskInfo>> ScanTasks(Page page, IEnumerable<(string url, string title)> areas)35 {36 var result = new List<TaskInfo>();37 foreach (var area in areas)38 {39 if (area.title == "Databases") continue; // Does not support SQL queries.40 if (area.title == "Python") continue; // Does not support multiple choice.41 Console.WriteLine($"Opening area {area.title}");42 var response = await page.GoToAsync(area.url);43 var dummy = await page.WaitForSelectorAsync("div.arcade-map--topic");44 Console.WriteLine($"Scanning area {area.title}");45 var topicList = await page.QuerySelectorAllAsync("div.arcade-map--topic");46 foreach (var topic in topicList)47 {48 var span = await topic.QuerySelectorAsync("span");49 var topicTitle = await (await span.GetPropertyAsync("innerText")).JsonValueAsync<string>();50 var taskList = await topic.QuerySelectorAllAsync("div.arcade-map--topic-details a.arcade-map--task");51 foreach (var task in taskList)52 {53 var taskUrl = await (await task.GetPropertyAsync("href")).JsonValueAsync<string>();54 var solvedText = await (await task.GetPropertyAsync("className")).JsonValueAsync<string>();55 var solved = !solvedText.Contains("-current") && !solvedText.Contains("-not-solved");56 var taskTitle = await (await (await task.QuerySelectorAsync("h3")).GetPropertyAsync("innerText")).JsonValueAsync<string>();57 result.Add(new TaskInfo(area.url, area.title, topicTitle, taskUrl, taskTitle, solved));58 }59 }60 }61 return result;62 }63 public static async Task RetrieveTask(Page page, TaskInfo task)64 {65 Console.Write($"Reading {task.Task} of {task.Topic}.");66 await page.GoToAsync(task.TaskUrl);67 Console.Write(".");68 await page.SetViewportAsync(new ViewPortOptions() { Height = 100000, Width = 8000, HasTouch = false, IsMobile = false });69 Console.Write(".");70 var source = await page.WaitForSelectorAsync("div.view-lines");71 Console.Write(".");72 task.Source = await (await source.GetPropertyAsync("innerText")).JsonValueAsync<string>();73 Console.Write(".");74 await page.SetViewportAsync(new ViewPortOptions() { Height = 800, Width = 1600, HasTouch = false, IsMobile = false });75 Console.Write(".");76 var desc = await page.QuerySelectorAsync("div.markdown");77 Console.Write(".");78 task.Description = await (await desc.GetPropertyAsync("innerText")).JsonValueAsync<string>();79 Console.Write(".");80 var index = task.Description.IndexOf("[C#] Syntax Tips");81 if (index > 0) task.Description = task.Description.Substring(0, index);82 if (Source.TestExists(task, out var _)) return; // No need to read tests.83 task.Tests = new List<string>();84 var list = await page.QuerySelectorAllAsync("div.accordion");85 Console.Write(".");86 foreach (var item in list)87 {88 var btn = await item.QuerySelectorAsync("div.accordion--head");89 Console.Write(".");90 PuppeteerSharp.ElementHandle body;91 do92 {93 await btn.ClickAsync();94 Console.Write(".");95 body = await item.QuerySelectorAsync("div.accordion--body");96 Console.Write(".");97 if (body == null) await Task.Delay(100);98 } while (body == null);99 string test;100 var warning = await body.QuerySelectorAsync("div.task-tests--warning");101 Console.Write(".");102 if (warning != null)103 {104 // The test example is too big, download it.105 var name = await (await btn.GetPropertyAsync("innerText")).JsonValueAsync<string>();106 Console.Write(".");107 name = name.Replace(' ', '-') + ".json";108 name = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads", name);109 if (File.Exists(name)) File.Delete(name);110 var download = await warning.QuerySelectorAsync("div.button");111 Console.Write(".");112 await download.ClickAsync();113 Console.Write(".");114 int limit = 80;115 while (limit-- > 0 && !File.Exists(name))116 {117 await Task.Delay(250);118 }119 if (File.Exists(name))120 {121 test = ReadJsonTest(name);122 }123 else124 {125 test = "Failed to download test " + name;126 task.Failed = true;127 }128 }129 else130 {131 var input = await body.QuerySelectorAsync("pre.task-tests--value");132 if (input == null) break;133 test = await (await input.GetPropertyAsync("innerText")).JsonValueAsync<string>();134 Console.Write(".");135 input = await body.QuerySelectorAsync("pre.-answer");136 Console.Write(".");137 test += "\nExpected Output: " + await (await input.GetPropertyAsync("innerText")).JsonValueAsync<string>();138 Console.Write(".");139 }140 task.Tests.Add(test);141 }142 Console.WriteLine("");143 }144 private static string ReadJsonTest(string filename)145 {146 var jsonText = File.ReadAllText(filename);147 var json = JsonSerializer.Deserialize(jsonText, typeof(object)) as JsonElement?;148 StringBuilder result = new StringBuilder();149 json.Value.TryGetProperty("input", out var input);...
BookReSellService.cs
Source:BookReSellService.cs
...119 await GlobalBrowser.CloseAsync();120 }121 static async Task<bool> CheckIfValid(Page page)122 {123 var missingElement = await page.QuerySelectorAsync(".missing-content");124 var resultTerm = await page.QuerySelectorAsync(".result__term");125 return missingElement == null && resultTerm == null;126 }127 static async Task<string> GetInnerHtmlFromQuery(Page page, string query)128 {129 var elementHandle = await page.QuerySelectorAsync(query);130 var jsHandle = await elementHandle.GetPropertyAsync("innerHTML");131 return TrimElementHandlerPropertyString(jsHandle);132 }133 static async Task<List<ElementHandle>> GetElementHandles(Page page, string query)134 {135 List<ElementHandle> elementHandles = new List<ElementHandle>();136 var elementsArray = await page.QuerySelectorAllAsync(query);137 elementHandles.AddRange(elementsArray);138 return elementHandles;139 }140 static async Task ParseVendorResultElementHandles(BookInfo book, List<VendorResult> vendorResults, List<ElementHandle> elementHandles)141 {142 foreach (var element in elementHandles)143 {...
Program.cs
Source:Program.cs
...70 Data data = new Data();71 await page.SetContentAsync(result.content);72 Thread.Sleep(500);73 string content = "", content2 = "";74 var elementHandle = await page.QuerySelectorAsync("span.d2edcug0.hpfvmrgz.qv66sw1b.c1et5uql.lr9zc1uh.a8c37x1j.keod5gw0.nxhoafnm.aigsh9s9.d3f4x2em.fe6kdd0r.mau55g9w.c8b282yb.iv3no6db.jq4qci2q.a3bd9o3v.knj5qynh.m9osqain.hzawbc8m");75 if (elementHandle != null)76 {77 try78 {79 content = await elementHandle.QuerySelectorAsync("span").EvaluateFunctionAsync<string>("node => node.innerText");80 }81 catch (Exception e1)82 {83 Console.WriteLine("error in getting content: " + e1.Message);84 }85 }86 if (content != "")87 {88 Thread.Sleep(500);89 try90 {91 content2 = await page.QuerySelectorAsync("div.kvgmc6g5.cxmmr5t8.oygrvhab.hcukyx3x.c1et5uql.ii04i59q").EvaluateFunctionAsync<string>("node => node.innerText");92 }93 catch (Exception e2)94 {95 Console.WriteLine("error in getting content: " + e2.Message);96 }97 data.author = content;98 data.posttext = content2;99 authorNamesAndText.Add(data);100 }101 }102 //print author and post list103 foreach (Data ap in authorNamesAndText)104 {105 Console.WriteLine("Author: " + ap.author);...
NavigateLogin.cs
Source:NavigateLogin.cs
...59 var response = await this.Page.GoToAsync(this.loginurl, new NavigationOptions60 {61 WaitUntil = new[] { WaitUntilNavigation.DOMContentLoaded },62 });63 this.elusername = await this.Page.QuerySelectorAsync("#user");64 this.elpassword = await this.Page.QuerySelectorAsync("input[name='password']");65 this.elbutton = await this.Page.QuerySelectorAsync("input.btn:nth-child(1)");66 if (this.elusername == null || this.elpassword == null || this.elbutton == null)67 {68 throw new Exception("NavigateLogin: Form input items missing.");69 }70 else71 {72 Console.WriteLine("Initialise Success.");73 }74 }75 private async Task ProcessAsync()76 {77 var usernameinput = await this.Page.QuerySelectorAsync("#user");78 await this.Page.EvaluateFunctionAsync($"yup => yup.value = '{this.Username}'", usernameinput);79 var passwordinput = await this.Page.QuerySelectorAsync("input[name='password']");80 await this.Page.EvaluateFunctionAsync($"mmhm => mmhm.value = '{this.Pasword}'", passwordinput);81 var form = await this.Page.QuerySelectorAsync("#loginForm");82 if (form == null)83 {84 throw new Exception("NavigateLogin: Page missing required login form.");85 }86 await this.Page.EvaluateFunctionAsync($"f => f.submit()", form);87 await this.Page.WaitForNavigationAsync(new NavigationOptions { WaitUntil = new[] { WaitUntilNavigation.Load } });88 await this.Page.SetRequestInterceptionAsync(true);89 this.Page.Request += this.DenyRequests;90 }91 private async Task Commit()92 {93 // finalise operations94 if (this.Page.Url == "http://www.property-guru.co.nz/gurux/render.php?action=main")95 {...
ElementHandleExtensions.cs
Source:ElementHandleExtensions.cs
...31 /// <typeparam name="T">The type of <see cref="ElementObject" /></typeparam>32 /// <param name="elementHandle">A <see cref="ElementHandle" /></param>33 /// <param name="selector">A selector to query element for</param>34 /// <returns>Task which resolves to the <see cref="ElementObject" /></returns>35 /// <seealso cref="ElementHandle.QuerySelectorAsync(string)"/>36 public static async Task<T> QuerySelectorAsync<T>(this ElementHandle elementHandle, string selector) where T : ElementObject37 {38 var result = await elementHandle.GuardFromNull().QuerySelectorAsync(selector).ConfigureAwait(false);39 return ProxyFactory.ElementObject<T>(elementHandle.GetPage(), result);40 }41 /// <summary>42 /// Evaluates the XPath expression relative to the element and returns an <see cref="ElementObject" /> array.43 /// If no elements match the expression, the return value resolve to <see cref="System.Array.Empty{T}"/>.44 /// </summary>45 /// <typeparam name="T">The type of <see cref="ElementObject" /></typeparam>46 /// <param name="elementHandle">A <see cref="ElementHandle" /></param>47 /// <param name="expression">Expression to evaluate <see href="https://developer.mozilla.org/en-US/docs/Web/API/Document/evaluate" /></param>48 /// <returns>Task which resolves to the <see cref="ElementObject" /> array</returns>49 /// <seealso cref="ElementHandle.XPathAsync(string)"/>50 public static async Task<T[]> XPathAsync<T>(this ElementHandle elementHandle, string expression) where T : ElementObject51 {52 var results = await elementHandle.GuardFromNull().XPathAsync(expression).ConfigureAwait(false);...
PuppeteerSharpRepoSpecs.cs
Source:PuppeteerSharpRepoSpecs.cs
...22 It should_be_the_first_search_result = () =>23 {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 {67 ElementHandle latest = page.QuerySelectorWithContentAsync("a[href*='releases'] span", @"v\d+\.\d\.\d").Await();68 return latest.TextContent();...
ProxyFactoryTests.cs
Source:ProxyFactoryTests.cs
...21 }22 [Fact]23 public async Task ElementObject_returns_proxy_of_type()24 {25 var elementHandle = await Page.QuerySelectorAsync(".tweet");26 var result = ProxyFactory.ElementObject<FakeElementObject>(Page, elementHandle);27 Assert.NotNull(result);28 Assert.IsAssignableFrom<FakeElementObject>(result);29 result = ProxyFactory.ElementObject<FakeElementObject>(Page, null);30 Assert.Null(result);31 }32 [Fact]33 public async Task ElementObject_returns_proxy_of_given_type()34 {35 var elementHandle = await Page.QuerySelectorAsync(".tweet");36 var result = ProxyFactory.ElementObject(typeof(FakeElementObject), Page, elementHandle);37 Assert.NotNull(result);38 Assert.IsAssignableFrom<FakeElementObject>(result);39 result = ProxyFactory.ElementObject(typeof(FakeElementObject), Page, null);40 Assert.Null(result);41 }42 [Fact]43 public async Task ElementObjectArray_returns_proxy_of_given_type()44 {45 var elementHandles = await Page.QuerySelectorAllAsync("div");46 var result = ProxyFactory.ElementObjectArray(typeof(FakeElementObject), Page, elementHandles);47 Assert.NotEmpty(result);48 Assert.All(result.Cast<ElementObject>(), x => Assert.IsAssignableFrom<FakeElementObject>(x));49 result = ProxyFactory.ElementObjectArray(typeof(FakeElementObject), Page, new ElementHandle[0]);...
QuerySelectorAsync
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 var elementHandle = await page.QuerySelectorAsync("input[name='q']");13 Console.WriteLine(elementHandle);14 }15 }16 }17}18using System;19using System.Threading.Tasks;20using PuppeteerSharp;21{22 {23 static async Task Main(string[] args)24 {25 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);26 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }))27 using (var page = await browser.NewPageAsync())28 {29 var elementHandle = await page.QuerySelectorAllAsync("input[name='q']");30 foreach (var item in elementHandle)31 {32 Console.WriteLine(item);33 }34 }35 }36 }37}38using System;39using System.Threading.Tasks;40using PuppeteerSharp;41{42 {43 static async Task Main(string[] args)44 {45 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);46 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }))47 using (var page = await browser.NewPageAsync())48 {49 var elementHandle = await page.QuerySelectorAsync("input[name='q']");50 Console.WriteLine(elementHandle);51 }52 }53 }54}
QuerySelectorAsync
Using AI Code Generation
1var page = await browser.NewPageAsync();2var searchBox = await page.QuerySelectorAsync("input[name='q']");3await searchBox.TypeAsync("PuppeteerSharp");4await page.ScreenshotAsync("example.png");5var page = await browser.NewPageAsync();6var searchBox = await page.QuerySelectorAsync("input[name='q']");7await searchBox.TypeAsync("PuppeteerSharp");8await page.ScreenshotAsync("example.png");9var page = await browser.NewPageAsync();10var searchBox = await page.QuerySelectorAsync("input[name='q']");11await searchBox.TypeAsync("PuppeteerSharp");12await page.ScreenshotAsync("example.png");13var page = await browser.NewPageAsync();14var searchBox = await page.QuerySelectorAsync("input[name='q']");15await searchBox.TypeAsync("PuppeteerSharp");16await page.ScreenshotAsync("example.png");17var page = await browser.NewPageAsync();18var searchBox = await page.QuerySelectorAsync("input[name='q']");19await searchBox.TypeAsync("PuppeteerSharp");20await page.ScreenshotAsync("example.png");21var page = await browser.NewPageAsync();22var searchBox = await page.QuerySelectorAsync("input[name='q']");23await searchBox.TypeAsync("PuppeteerSharp");24await page.ScreenshotAsync("example.png");25var page = await browser.NewPageAsync();
QuerySelectorAsync
Using AI Code Generation
1var page = await browser.NewPageAsync();2var searchBox = await page.QuerySelectorAsync("input[name=q]");3await searchBox.TypeAsync("Hello World!");4await page.Keyboard.PressAsync("Enter");5await page.WaitForNavigationAsync();6await page.ScreenshotAsync("1.png");7await browser.CloseAsync();8var page = await browser.NewPageAsync();9var searchBox = await page.QuerySelectorAsync("input[name=q]");10await searchBox.TypeAsync("Hello World!");11await page.Keyboard.PressAsync("Enter");12await page.WaitForNavigationAsync();13await page.ScreenshotAsync("2.png");14await browser.CloseAsync();15var page = await browser.NewPageAsync();16var searchBox = await page.MainFrame.QuerySelectorAsync("input[name=q]");17await searchBox.TypeAsync("Hello World!");18await page.Keyboard.PressAsync("Enter");19await page.WaitForNavigationAsync();20await page.ScreenshotAsync("3.png");21await browser.CloseAsync();22var page = await browser.NewPageAsync();23var searchBox = await page.QuerySelectorAsync("input[name=q]");24await searchBox.TypeAsync("Hello World!");25await page.Keyboard.PressAsync("Enter");26await page.WaitForNavigationAsync();27await page.ScreenshotAsync("4.png");28await browser.CloseAsync();29var page = await browser.NewPageAsync();30var searchBox = await page.QuerySelectorAsync("input[name=q]");31await searchBox.TypeAsync("Hello World!");32await page.Keyboard.PressAsync("Enter");33await page.WaitForNavigationAsync();34await page.ScreenshotAsync("5.png");35await browser.CloseAsync();36var page = await browser.NewPageAsync();
QuerySelectorAsync
Using AI Code Generation
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 LaunchOptions9 {10 });11 var page = await browser.NewPageAsync();12 await page.ClickAsync("input[name='q']");13 await page.Keyboard.TypeAsync("PuppeteerSharp");14 await page.ClickAsync("input[name='btnK']");15 await page.WaitForNavigationAsync();16 await page.WaitForSelectorAsync("div#res");17 var result = await page.QuerySelectorAsync("div#res");18 var text = await result.EvaluateFunctionAsync<string>("element => element.innerText");19 Console.WriteLine(text);20 await browser.CloseAsync();21 }22 }23}
QuerySelectorAsync
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 LaunchOptions10 {11 }))12 using (var page = await browser.NewPageAsync())13 {14 var searchInput = await page.QuerySelectorAsync("input[name='q']");15 await searchInput.TypeAsync("puppeteer-sharp");16 await searchInput.FocusAsync();17 await page.Keyboard.PressAsync("Enter");18 await page.WaitForNavigationAsync();19 var searchResult = await page.QuerySelectorAsync("h3 a");20 await searchResult.ClickAsync();21 await page.WaitForNavigationAsync();22 var element = await page.QuerySelectorAsync("a[href='
QuerySelectorAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static void Main(string[] args)7 {8 Console.WriteLine("Hello World!");9 new Program().DoWork().Wait();10 }11 public async Task DoWork()12 {13 var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false });14 var page = await browser.NewPageAsync();15 var element = await page.QuerySelectorAsync("h1");16 string textContent = await element.EvaluateFunctionAsync<string>("element => element.textContent");17 Console.WriteLine(textContent);18 }19 }20}21using System;22using System.Threading.Tasks;23using PuppeteerSharp;24{25 {26 static void Main(string[] args)27 {28 Console.WriteLine("Hello World!");29 new Program().DoWork().Wait();30 }31 public async Task DoWork()32 {
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!!