How to use WaitForSelectorAsync method of PuppeteerSharp.Page class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Page.WaitForSelectorAsync

Authorization.cs

Source:Authorization.cs Github

copy

Full Screen

...57 WaitForSelectorOptions WaitForSelectorTimeout = new WaitForSelectorOptions { Timeout = DefaultTimeout };58 Log.Information($"DefaultTimeout: {p.DefaultTimeout}");59 Log.Information($"DefaultNavigationTimeout: {p.DefaultNavigationTimeout}");60 const string button = "body > app-root > n3-grid > app-login > div > div.notice > div > app-login-form > div > button";61 await p.WaitForSelectorAsync(button, WaitForSelectorTimeout);62 await System.Threading.Tasks.Task.Delay(10000);63 await p.ClickAsync(button);64 Log.Information("Первый клик {Button}: успешно!", "Войти с ЕСИА");65 Log.Information($"{timer.ElapsedMilliseconds}");66 timer.Restart();67 p = await GetPage(browser, "https://esia.gosuslugi.ru");68 Log.Information($"DefaultTimeout: {p.DefaultTimeout}");69 Log.Information($"DefaultNavigationTimeout: {p.DefaultNavigationTimeout}");70 // Авторизация71 await p.WaitForSelectorAsync("#mobileOrEmail", WaitForSelectorTimeout);72 await p.FocusAsync("#mobileOrEmail");73 await p.Keyboard.TypeAsync(ConfigJson.Login);74 Log.Information($"Login: {timer.ElapsedMilliseconds}");75 timer.Restart();76 await p.WaitForSelectorAsync("#password", WaitForSelectorTimeout);77 await p.FocusAsync("#password");78 await p.Keyboard.TypeAsync(ConfigJson.Password);79 Log.Information($"Password: {timer.ElapsedMilliseconds}");80 timer.Restart();81 await p.WaitForSelectorAsync("#loginByPwdButton > span", WaitForSelectorTimeout);82 await p.ClickAsync("#loginByPwdButton > span");83 Log.Information($"ClickAuthorizationButton: {timer.ElapsedMilliseconds}");84 Log.Information("Авторизация: успешно!");85 timer.Stop();86 /* Куки нужны для того, чтобы сайт меня опознал87 * при отправке http-запроса на сервер эл. дневника */88 // 10 попыток получения cookie.89 Cookie cookie;90 int count = 0;91 int attempts = (DefaultTimeout / 1000);92 do93 {94 if (count > attempts) throw new Exception("Cookie X-JMT-Token is not present.");95 await System.Threading.Tasks.Task.Delay(1000);...

Full Screen

Full Screen

BotDavid.cs

Source:BotDavid.cs Github

copy

Full Screen

...25 var page = await browser.PagesAsync();26 await page[0].GoToAsync("https://lvaction.com");27 await page[0].SetViewportAsync(new ViewPortOptions() {Width = viewportWidth, Height = viewportHeight});28 string ws = browser.WebSocketEndpoint;29 await page[0].WaitForSelectorAsync(".logo_area_right #account");30 await page[0].ClickAsync(".logo_area_right #account");31 await page[0].TypeAsync(".logo_area_right #account", userName);32 await page[0].WaitForSelectorAsync(".logo_area_right #password");33 await page[0].ClickAsync(".logo_area_right #password");34 await page[0].TypeAsync(".logo_area_right #password", password);35 await page[0].WaitForSelectorAsync(".logo_area_right #login_submit");36 await page[0].ClickAsync(".logo_area_right #login_submit");37 await page[0].WaitForNavigationAsync();38 // click bar menu39 await page[0].WaitForSelectorAsync(40 ".row > .col-4 > .burger-container > #burger > .btmBar"41 );42 await page[0].ClickAsync(".row > .col-4 > .burger-container > #burger > .btmBar");43 //live casino mobile44 await page[0].WaitForSelectorAsync(45 "#ctl00_ctl00_MobileMenu #ctl00_ctl00_LiveCasinoMobile"46 );47 await Task.Delay(3000);48 await page[0].ClickAsync("#ctl00_ctl00_MobileMenu #ctl00_ctl00_LiveCasinoMobile");49 50 await Task.Delay(3000);51 page = await browser.PagesAsync();52 page[1].SetViewportAsync(new ViewPortOptions() {Width = viewportWidth+10, Height = viewportHeight+10});53 // click on pick button54 await page[1]55 .WaitForSelectorAsync(".balance > .ng-scope > .manualtransfer > .amounts > .btn:nth-child(4)");56 await page[1].ClickAsync(".balance > .ng-scope > .manualtransfer > .amounts > .btn:nth-child(4)");57 // click on input box 58 await page[1]59 .WaitForSelectorAsync(".balance > .ng-scope > .manualtransfer > .ng-pristine > .ng-pristine");60 await page[1].ClickAsync(".balance > .ng-scope > .manualtransfer > .ng-pristine > .ng-pristine");61 // enter amount62 await page[1].TypeAsync(63 ".balance > .ng-scope > .manualtransfer > .ng-pristine > .ng-pristine",64 amountTransfer.ToString()65 );66 // click on transfer button67 await page[1].WaitForSelectorAsync(".balance > .ng-scope > .manualtransfer > .ng-valid > .btn");68 await page[1].ClickAsync(".balance > .ng-scope > .manualtransfer > .ng-valid > .btn");69 // roulette tab70 await page[1].WaitForSelectorAsync(71 "body > .ng-scope > .container > .ng-scope:nth-child(2) > .ng-binding"72 );73 await page[1].ClickAsync(74 "body > .ng-scope > .container > .ng-scope:nth-child(2) > .ng-binding"75 );76 // click on routlet 1-100 $$ WE NEED TO CHANGE THIS77 await page[1].WaitForSelectorAsync(78 ".col:nth-child(1) > .game > .limit > .ng-scope:nth-child(1) > .box"79 );80 await page[1].ClickAsync(81 $".col: nth - child(1) > .game > .limit > .ng - scope:nth - child({table.ToString()}) > .box"82 );83 await page[1].WaitForNavigationAsync();84 page = await browser.PagesAsync();85 return page[2];86 }87 catch88 {89 return false;90 }91 }...

Full Screen

Full Screen

Program.cs

Source:Program.cs Github

copy

Full Screen

...39 var adBtn = await page.QuerySelectorAsync(".ytp-ad-skip-button");40 if (adBtn != null) {41 await adBtn.ClickAsync();42 }43 var playBtn = await page.WaitForSelectorAsync("#play-pause-button");44 var prevBtn = await page.WaitForSelectorAsync(".previous-button");45 var nextBtn = await page.WaitForSelectorAsync(".next-button");46 var title = await page.WaitForSelectorAsync(".title.ytmusic-player-bar");47 var progress = await page.WaitForSelectorAsync("#progress-bar");48 while (true) {49 if (token.IsCancellationRequested) break;50 var read = Console.ReadLine();51 if (read == "ad") {52 var ad = await page.QuerySelectorAsync(".ytp-ad-skip-button");53 if (ad != null) {54 await ad.ClickAsync();55 Console.WriteLine("skipped");56 }57 }58 if (read == "reload") {59 playBtn = await page.WaitForSelectorAsync("#play-pause-button");60 prevBtn = await page.WaitForSelectorAsync(".previous-button");61 nextBtn = await page.WaitForSelectorAsync(".next-button");62 title = await page.WaitForSelectorAsync(".title.ytmusic-player-bar");63 progress = await page.WaitForSelectorAsync("#progress-bar");64 }65 if (read == "play") {66 await playBtn.ClickAsync();67 }68 if (read == "prev") {69 await prevBtn.ClickAsync();70 }71 if (read == "next") {72 await nextBtn.ClickAsync();73 }74 if (read == "isplaying") {75 Console.WriteLine(await IsPlaying());76 }77 if (read == "title") {...

Full Screen

Full Screen

BaseAuthUIFixture.cs

Source:BaseAuthUIFixture.cs Github

copy

Full Screen

...47 Thread.Sleep(delay);48 if(OperatingSystem.IsWindows())49 await Page.ConfirmScreenshot(screensName).ConfigureAwait(false);50 response.Url.Should().Contain("login.microsoftonline.com");51 await Page.WaitForSelectorAsync("input[name='loginfmt']").ConfigureAwait(false);52 await Page.Keyboard.SendCharacterAsync(TestGoodUserName).ConfigureAwait(false);53 await Page.Keyboard.PressAsync(Key.Enter).ConfigureAwait(false);54 await Page.WaitForSelectorAsync("input[name='passwd']:not(.moveOffScreen)").ConfigureAwait(false);55 await Page.Keyboard.SendCharacterAsync(TestPassword).ConfigureAwait(false);56 await Page.Keyboard.PressAsync(Key.Enter).ConfigureAwait(false);57 await Page.WaitForSelectorAsync("input[id='idSIButton9']").ConfigureAwait(false); ;58 Thread.Sleep(delay);59 if (OperatingSystem.IsWindows())60 await Page.ConfirmScreenshot(screensName).ConfigureAwait(false);61 await Page.Keyboard.PressAsync(Key.Enter).ConfigureAwait(false);62 await Page.GoToAsync(AuthUrl, options: new NavigationOptions { WaitUntil = new[] { WaitUntilNavigation.Networkidle0 } }).ConfigureAwait(false);63 //response = await page.WaitForNavigationAsync().ConfigureAwait(false);64 Authorized = true;65 }66 else67 {68 response = await Page.GoToAsync(AuthUrl).ConfigureAwait(false); ;69 }70 return response;71 }...

Full Screen

Full Screen

pay.cshtml.cs

Source:pay.cshtml.cs Github

copy

Full Screen

...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

AvitoPostParser.cs

Source:AvitoPostParser.cs Github

copy

Full Screen

...43 };44 }45 private async Task<string> GetAuthorName(PuppeteerSharp.Page page)46 {47 var sellerInfoName = await page.WaitForSelectorAsync(".seller-info-name.js-seller-info-name a").EvaluateFunctionAsync<string>("element => element.innerHTML");48 sellerInfoName = sellerInfoName.Trim();49 var sellerInfoValueElement = await page.QuerySelectorAsync("div.seller-info-label + div.seller-info-value");50 if (sellerInfoValueElement != null)51 {52 var sellerInfoValue = (await sellerInfoValueElement.EvaluateFunctionAsync<string>("element => element.innerHTML")).Trim();53 sellerInfoName += ": " + sellerInfoValue;54 }55 return sellerInfoName;56 }57 private async Task<string> GetPhoneNumber(PuppeteerSharp.Page page)58 {59 string phoneImage = await page.WaitForSelectorAsync("div[data-marker='phone-popup/content'] img[data-marker='phone-popup/phone-image']").EvaluateFunctionAsync<string>("element => element.src");60 string imageStr = phoneImage.Substring(phoneImage.IndexOf(",") + 1).Trim();61 byte[] imageByte = System.Convert.FromBase64String(imageStr);62 using (var engine = new TesseractEngine("./tessdata", "eng", EngineMode.Default))63 {64 using (var memoryStream = new MemoryStream(imageByte))65 {66 var file = Pix.LoadFromMemory(memoryStream.ToArray());67 var page1 = engine.Process(file);68 return page1.GetText().Trim();69 }70 }71 }72 }73}...

Full Screen

Full Screen

Browser.cs

Source:Browser.cs Github

copy

Full Screen

...41 {42 var pages = await browser.PagesAsync();43 var page = pages[0];44 await page.GoToAsync(AppConfig.tiqaUrl);45 var un = await page.WaitForSelectorAsync(AppConfig.unFld);46 var pw = await page.WaitForSelectorAsync(AppConfig.pwFld);47 var lgn = await page.WaitForSelectorAsync(AppConfig.lgnBtn);48 await un.TypeAsync(AppConfig.un);49 await pw.TypeAsync(AppConfig.pw);50 await lgn.ClickAsync();51 await page.WaitForNavigationAsync();52 var cks = await page.GetCookiesAsync();53 AppConfig.cks = cks.ToList();//.Where(c => c.Domain == new Uri(page.Url).Host).ToList();54 AppConfig.sessId = AppConfig.cks.Where(c => c.Name == AppConfig.sessIdName).FirstOrDefault().Value;55 AppConfig.WriteOut($">> session id for crawl set to {AppConfig.sessId}");56 AppConfig.crawlStartUri = page.Url;57 return true;58 }59 catch(NavigationException ex)60 {61 AppConfig.ErrHand(ex, $"XX failed to navigate to url");...

Full Screen

Full Screen

BrowserTests.cs

Source:BrowserTests.cs Github

copy

Full Screen

...45 if (e.Message.Type == ConsoleType.Error)46 hasError = true;47 }48 await page.GoToAsync(BaseAddress);49 var selector = await page.WaitForSelectorAsync("div.table-responsive > table > tbody > tr:nth-child(1) > td:nth-child(3)");50 (await selector.InnerTextAsync()).ShouldBe("Astrix Mariette");51 hasError.ShouldBeFalse();52 await PrintPerf(page);53 }54 }55}...

Full Screen

Full Screen

WaitForSelectorAsync

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static void Main(string[] args)7 {8 MainAsync().GetAwaiter().GetResult();9 }10 static async Task MainAsync()11 {12 var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false });13 var page = await browser.NewPageAsync();14 await page.WaitForSelectorAsync("input[name='q']");15 await page.TypeAsync("input[name='q']", "Puppeteer");16 await page.ClickAsync("input[value='Google Search']");17 await page.WaitForNavigationAsync();18 await page.ScreenshotAsync("google.png");19 await browser.CloseAsync();20 }21 }22}23using System;24using System.Threading.Tasks;25using PuppeteerSharp;26{27 {28 static void Main(string[] args)29 {30 MainAsync().GetAwaiter().GetResult();31 }32 static async Task MainAsync()33 {34 var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false });35 var page = await browser.NewPageAsync();36 await page.WaitForSelectorAsync("input[name='q']");37 await page.TypeAsync("input[name='q']", "Puppeteer");38 await page.ClickAsync("input[value='Google Search']");39 await page.WaitForNavigationAsync();40 await page.ScreenshotAsync("google.png");41 var frame = page.MainFrame;42 await frame.WaitForSelectorAsync("div.g");43 await frame.ScreenshotAsync("google2.png");44 await browser.CloseAsync();45 }46 }47}48using System;49using System.Threading.Tasks;50using PuppeteerSharp;51{52 {53 static void Main(string[] args)54 {55 MainAsync().GetAwaiter().GetResult();56 }57 static async Task MainAsync()58 {59 var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false });60 var page = await browser.NewPageAsync();

Full Screen

Full Screen

WaitForSelectorAsync

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 LaunchOptions9 {10 });11 var page = await browser.NewPageAsync();12 await page.WaitForSelectorAsync("input[name='btnK']");13 Console.WriteLine("Search button is visible");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 {25 var browser = await Puppeteer.LaunchAsync(new LaunchOptions26 {27 });28 var page = await browser.NewPageAsync();29 await page.WaitForSelectorAsync("input[name='btnK']", new WaitForSelectorOptions30 {31 });32 Console.WriteLine("Search button is visible");33 await browser.CloseAsync();34 }35 }36}37using System;38using System.Threading.Tasks;39using PuppeteerSharp;40{41 {42 static async Task Main(string[] args)43 {44 var browser = await Puppeteer.LaunchAsync(new LaunchOptions45 {46 });47 var page = await browser.NewPageAsync();48 await page.WaitForSelectorAsync("input[name='btnK']", new WaitForSelectorOptions49 {50 });51 Console.WriteLine("Search button is visible");52 await browser.CloseAsync();53 }54 }55}

Full Screen

Full Screen

WaitForSelectorAsync

Using AI Code Generation

copy

Full Screen

1var page = await browser.NewPageAsync();2await page.WaitForSelectorAsync("input[name=q]");3await page.TypeAsync("input[name=q]", "PuppeteerSharp");4await page.ClickAsync("input[name=btnK]");5await page.WaitForNavigationAsync();6await page.ScreenshotAsync("screenshot.png");7var page = await browser.NewPageAsync();8var frame = page.MainFrame;9await frame.WaitForSelectorAsync("input[name=q]");10await frame.TypeAsync("input[name=q]", "PuppeteerSharp");11await frame.ClickAsync("input[name=btnK]");12await page.WaitForNavigationAsync();13await page.ScreenshotAsync("screenshot.png");14var page = await browser.NewPageAsync();15var elementHandle = await page.WaitForSelectorAsync("input[name=q]");16await elementHandle.TypeAsync("PuppeteerSharp");17await elementHandle.ClickAsync();18await page.WaitForNavigationAsync();19await page.ScreenshotAsync("screenshot.png");20var page = await browser.NewPageAsync();21var jSHandle = await page.WaitForSelectorAsync("input[name=q]");22await jSHandle.TypeAsync("PuppeteerSharp");23await jSHandle.ClickAsync();24await page.WaitForNavigationAsync();25await page.ScreenshotAsync("screenshot.png");26var page = await browser.NewPageAsync();27var iWaitTask = await page.WaitForSelectorAsync("input[name=q]");28await iWaitTask.TypeAsync("PuppeteerSharp");29await iWaitTask.ClickAsync();30await page.WaitForNavigationAsync();31await page.ScreenshotAsync("screenshot.png");32var page = await browser.NewPageAsync();

Full Screen

Full Screen

WaitForSelectorAsync

Using AI Code Generation

copy

Full Screen

1var page = await browser.NewPageAsync();2var element = await page.WaitForSelectorAsync("input[name='q']");3await element.TypeAsync("PuppeteerSharp");4await page.Keyboard.PressAsync("Enter");5await page.WaitForNavigationAsync();6await page.ScreenshotAsync("example.png");7var page = await browser.NewPageAsync();8var frame = await page.MainFrame.WaitForSelectorAsync("iframe");9await frame.WaitForSelectorAsync("input[name='q']");10await frame.TypeAsync("PuppeteerSharp");11await page.Keyboard.PressAsync("Enter");12await page.WaitForNavigationAsync();13await page.ScreenshotAsync("example.png");14var page = await browser.NewPageAsync();15var element = await page.WaitForSelectorAsync("input[name='q']");16var frame = await element.WaitForSelectorAsync("iframe");17await frame.WaitForSelectorAsync("input[name='q']");18await frame.TypeAsync("PuppeteerSharp");19await page.Keyboard.PressAsync("Enter");20await page.WaitForNavigationAsync();21await page.ScreenshotAsync("example.png");22var page = await browser.NewPageAsync();23var element = await page.WaitForSelectorAsync("input[name='q']");24var frame = await element.EvaluateFunctionHandleAsync("element => element.contentDocument.querySelector('iframe')");25await frame.WaitForSelectorAsync("input[name='q']");26await frame.TypeAsync("PuppeteerSharp");27await page.Keyboard.PressAsync("Enter");28await page.WaitForNavigationAsync();29await page.ScreenshotAsync("example.png");30var page = await browser.NewPageAsync();31var element = await page.WaitForSelectorAsync("input[name='q']");32var frame = await element.EvaluateFunctionHandleAsync("element => element.contentDocument.querySelector('iframe')");33var input = await frame.EvaluateFunctionHandleAsync("frame => frame

Full Screen

Full Screen

WaitForSelectorAsync

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static void Main(string[] args)7 {8 Test().Wait();9 }10 static async Task Test()11 {12 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions13 {14 Args = new string[] { "--start-maximized" }15 }))16 {17 var page = await browser.NewPageAsync();18 await page.WaitForSelectorAsync("input[name='q']");19 await Task.Delay(5000);20 await page.ClickAsync("input[name='q']");

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.

Most used method in Page

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful