How to use QuerySelectorAsync method of PuppeteerSharp.Frame class

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

FacebookRegistration.cs

Source:FacebookRegistration.cs Github

copy

Full Screen

...80 _data.ErrMsg = BotMessages.PhoneNumberNotAcceptMessage;81 return;82 }83 await page.WaitForTimeoutAsync(3000);84 var eVerify = await page.QuerySelectorAsync("#checkpointSubmitButton");85 if (eVerify != null) { 86 await eVerify.ClickAsync();87 try { await page.WaitForNavigationAsync(_navigationOptions); } catch { }88 //var pages = await page.Browser.PagesAsync();89 //page = pages[0];90 }91 //await SolveRecaptcha(page);92 await FillPhoneAgain(page);93 var phoneNumberValidation = await _smsService.GetSmsValidation(_requestId);94 Log.Info($"phoneNumberValidation: {JsonConvert.SerializeObject(phoneNumberValidation)}");95 if (phoneNumberValidation != null)96 {97 await _smsService.SetSmsValidationSuccess(_requestId);98 const string selSmsCode = "input#code_in_cliff";99 await page.ClickAsync(selSmsCode);100 await page.TypeAsync(selSmsCode, phoneNumberValidation.Code);101 await page.ClickAsync("div.uiInterstitialContent button");102 await page.WaitForSelectorAsync("div._t a", new WaitForSelectorOptions { Timeout = 20000 });103 await page.ClickAsync("div._t a");104 await page.WaitForNavigationAsync();105 await page.WaitForTimeoutAsync(3000);106 _data.Success = true;107 }108 else await _smsService.SetNumberFail(_requestId);109 }110 #region Steps111 private async Task FillRegistrationData(Page page)112 {113 var _typeOptions = new TypeOptions { Delay = 50 };114 var eSignUp = await page.QuerySelectorAsync("#signup-button");115 if (eSignUp != null) await eSignUp.ClickAsync();116 #region Name117 await page.WaitForSelectorAsync("input[name=firstname]", new WaitForSelectorOptions { Visible = true });118 await page.ClickAsync("input[name=firstname]");119 await page.TypeAsync("input[name=firstname]", _data.Firstname, _typeOptions);120 await page.TypeAsync("input[name=lastname]", _data.Lastname, _typeOptions);121 #endregion122 await page.TypeAsync("input[name=reg_email__]", _data.Phone, _typeOptions);123 await page.TypeAsync("input[name=reg_passwd__]", _data.Password, _typeOptions);124 await page.WaitForTimeoutAsync(500);125 await page.ClickAsync("select#day");126 await page.WaitForTimeoutAsync(500);127 await page.SelectAsync("select#day", $"{_data.BirthDate.Day}");128 await page.ClickAsync("select#month");129 await page.WaitForTimeoutAsync(500);130 await page.SelectAsync("select#month", $"{_data.BirthDate.Month}");131 await page.WaitForTimeoutAsync(500);132 await page.ClickAsync("select#year");133 await page.SelectAsync("select#year", $"{_data.BirthDate.Year}");134 if (_data.Sex == SexCode.Female) await page.ClickAsync("input[name=sex][value='1']");135 if (_data.Sex == SexCode.Male) await page.ClickAsync("input[name=sex][value='2']");136 }137 private async Task SolveRecaptcha(Page page, int deep = 0)138 {139 if (deep >= 2) return;140 var eGotoRecapthcha = await page.QuerySelectorAsync("#checkpointSubmitButton");141 if (eGotoRecapthcha == null) return;142 await eGotoRecapthcha.ClickAsync();143 await page.WaitForTimeoutAsync(2000);144 var eRecaptcha = await page.QuerySelectorAsync("#captcha_response");145 if (eRecaptcha != null)146 {147 //var targets = page.Browser.Targets();148 var anticaptchaScriptText = File.ReadAllText(Path.GetFullPath(".\\Data\\init.js"));149 anticaptchaScriptText = anticaptchaScriptText.Replace("YOUR-ANTI-CAPTCHA-API-KEY", AntiCaptchaOnlineApi.GetApiKeyAnticaptcha());150 await page.EvaluateExpressionAsync(anticaptchaScriptText);151 anticaptchaScriptText = File.ReadAllText(Path.GetFullPath(".\\Data\\recaptchaaifb.js"));152 await page.EvaluateExpressionAsync(anticaptchaScriptText);153 //targets[8].154 //await page.AddScriptTagAsync(new AddTagOptions { Content= anticaptchaScriptText });155 //await page.WaitForSelectorAsync(".antigate_solver.solved", new WaitForSelectorOptions { Timeout = 120 * 1000 });156 // await page.ClickAsync("input[type=submit]");157 //await page.WaitForNavigationAsync();158 try { await page.WaitForTimeoutAsync(90 * 1000); } catch { }159 await SolveRecaptcha(page, ++deep);160 }161 }162 private async Task ClickSubmit(Page page)163 {164 var elSignUp = await page.QuerySelectorAsync("button[type=submit]");165 await elSignUp.ClickAsync();166 await page.WaitForTimeoutAsync(500);167 }168 private async Task FillPhoneAgain(Page page)169 {170 var eSendCode = await page.QuerySelectorAsync("button[name='submit[set_contact_point_primary_button]']");171 if (eSendCode == null) return;172 var selCountries = "ul[role=menu] a>span>span";173 var eCountries = await page.QuerySelectorAllAsync(selCountries);174 if (eCountries == null) return;175 var jsAltMailList = $@"Array.from(document.querySelectorAll('{selCountries}')).map(a => a.innerText);";176 var countries = await page.EvaluateExpressionAsync<string[]>(jsAltMailList);177 // код страны +44178 var country = countries.FirstOrDefault(z => z.Contains($"(+{_countryPrefix})"));179 var idx = Array.IndexOf(countries, country);180 if (eCountries.Length > idx) await eCountries[idx].ClickAsync();181 var ePhone = await page.QuerySelectorAsync("input[type=tel]");182 await ePhone.TypeAsync(_data.Phone.Replace($"+{_countryPrefix}", ""), _typeOptions);183 await eSendCode.ClickAsync();184 }185 #endregion186 #region else187 private async static Task SetHooks(Page page)188 {189 //await page.SetRequestInterceptionAsync(true);190 //page.Request += Page_Request;191 //page.Response += Page_Response;192 page.FrameAttached += Page_FrameAttached;193 page.FrameNavigated += Page_FrameNavigated;194 page.WorkerCreated += Page_WorkerCreated;195 }...

Full Screen

Full Screen

Form1.cs

Source:Form1.cs Github

copy

Full Screen

...207 //public async Task<ElementHandle> GetElement_ByCssSelector(string selector)208 //{209 // ElementHandle ele;210 // if (usingFrame)211 // ele = await frame.QuerySelectorAsync(selector);212 // else213 // ele = await page.QuerySelectorAsync(selector);214 // return ele;215 //}216 //public async Task<ElementHandle[]> GetAllElement_ByCssSelector(string selector)217 //{218 // ElementHandle[] eles;219 // if (usingFrame)220 // eles = await frame.QuerySelectorAllAsync(selector);221 // else222 // eles = await page.QuerySelectorAllAsync(selector);223 // return eles;224 //}225 //public async Task<bool> elementExist_ByCssSelector(string selector)226 //{227 // ElementHandle ele;228 // if (usingFrame)229 // ele = await frame.QuerySelectorAsync(selector);230 // else231 // ele = await page.QuerySelectorAsync(selector);232 // if (ele != null) return true;233 // else return false;234 //}235 //public async Task ExecuteJS_Script(string jsText)236 //{237 // if (usingFrame)238 // await frame.EvaluateExpressionAsync(jsText);239 // else240 // await page.EvaluateExpressionAsync(jsText);241 // //if (usingFrame)242 // // await frame.EvaluateFunctionAsync(jsText);243 // //else244 // // await page.EvaluateFunctionAsync(jsText);245 //}...

Full Screen

Full Screen

BlazorTest.cs

Source:BlazorTest.cs Github

copy

Full Screen

...50 page.Url.Should().EndWith("counter");5152 await page.ClickAsync(".btn-primary");5354 var pElement = await page.QuerySelectorAsync(".content p");55 pElement.Should().NotBeNull();5657 var prop = await pElement.GetPropertyAsync("innerHTML").Result.JsonValueAsync();58 prop.Should().Be("Current count: 1");5960 Console.WriteLine("Done. Closing browser...");61 await browser.CloseAsync();62 }63 }6465 /*public class Documentation66 {67 [Fact]68 public async Task download_Chromium()69 {70 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);71 }7273 [Fact]74 public async Task<Browser> Browser()75 {76 var browser = await Puppeteer.LaunchAsync(new LaunchOptions77 {78 Headless = true79 });8081 return browser;82 }8384 [Fact]85 public async Task close_Browser()86 {87 var browser = await Browser();8889 await browser.CloseAsync();90 }9192 [Fact]93 public async Task using_Browser()94 {95 var options = new LaunchOptions { Headless = true };9697 using(var browser = await Puppeteer.LaunchAsync(options))98 {99 // ...100 }101 }102103 [Fact]104 public async Task<Page> Page()105 {106 var browser = await Browser();107108 var page = await browser.NewPageAsync();109110 return page;111 }112113 [Fact]114 public async Task close_Page()115 {116 var page = await Page();117118 await page.CloseAsync();119 }120121 [Fact]122 public async Task using_Page()123 {124 var browser = await Browser();125126 using(var page = await browser.NewPageAsync())127 {128 // ...129 }130 }131132 [Fact]133 public async Task navigation()134 {135 var page = await Page();136137 await page.GoToAsync("https://github.com/kblok/puppeteer-sharp");138 await page.GoBackAsync();139 await page.GoForwardAsync();140 await page.ReloadAsync();141 }142143 [Fact]144 public async Task timeout()145 {146 var page = await Page();147148 var timeout = TimeSpan.FromSeconds(30).Milliseconds; // default value149150 page.DefaultNavigationTimeout = timeout;151 //page.DefaultWaitForTimeout = timeout;152153 var options = new NavigationOptions { Timeout = timeout };154155 await page.GoToAsync("https://github.com/kblok/puppeteer-sharp", options);156 await page.GoBackAsync(options);157 await page.GoForwardAsync(options);158 await page.ReloadAsync(options);159 }160161 [Fact]162 public async Task wait()163 {164 var page = await Page();165166 var timeout = TimeSpan.FromSeconds(3).Milliseconds;167168 var request = page.WaitForRequestAsync("https://github.com/kblok/puppeteer-sharp", new WaitForOptions { Timeout = timeout });169 var response = page.WaitForResponseAsync("https://github.com/kblok/puppeteer-sharp", new WaitForOptions { Timeout = timeout });170171 await page.GoToAsync("https://github.com/kblok/puppeteer-sharp");172173 await Task.WhenAll(request, response);174175 await page.ClickAsync("h1 > strong > a");176 await page.WaitForNavigationAsync(new NavigationOptions { Timeout = timeout });177178 await page.WaitForExpressionAsync("1 + 1 === 2", new WaitForFunctionOptions { Timeout = timeout });179 await page.WaitForFunctionAsync("() => window.location.href === 'https://github.com/kblok/puppeteer-sharp'", new WaitForFunctionOptions { Timeout = timeout });180 await page.WaitForSelectorAsync("#readme", new WaitForSelectorOptions { Timeout = timeout });181 await page.WaitForXPathAsync("//*[@id='readme']", new WaitForSelectorOptions { Timeout = timeout });182183 await page.WaitForTimeoutAsync(timeout);184185 // WaitUntilNavigation186 new NavigationOptions().WaitUntil = new []187 {188 WaitUntilNavigation.Load,189 WaitUntilNavigation.DOMContentLoaded,190 WaitUntilNavigation.Networkidle0,191 WaitUntilNavigation.Networkidle2192 };193194 // Frame195 var frame = page.MainFrame;196197 await frame.WaitForExpressionAsync("1 + 1 === 2", new WaitForFunctionOptions { Timeout = timeout });198 await frame.WaitForFunctionAsync("() => window.location.href === 'https://github.com/kblok/puppeteer-sharp'", new WaitForFunctionOptions { Timeout = timeout });199 await frame.WaitForSelectorAsync("#readme", new WaitForSelectorOptions { Timeout = timeout });200 await frame.WaitForXPathAsync("//*[@id='readme']", new WaitForSelectorOptions { Timeout = timeout });201202 await frame.WaitForTimeoutAsync(timeout);203 }204205 [Fact]206 public async Task values_from_Page()207 {208 var page = await Page();209210 var url = page.Url;211 var title = await page.GetTitleAsync();212 var content = await page.GetContentAsync();213 var cookies = await page.GetCookiesAsync();214 }215216 [Fact]217 public async Task form()218 {219 var page = await Page();220221 await page.GoToAsync("http://toolsqa.com/automation-practice-form/");222223 // input / text224 await page.TypeAsync("input[name='firstname']", "Puppeteer");225226 // input / radio227 await page.ClickAsync("#exp-6");228229 // input / checkbox230 await page.ClickAsync("#profession-1"); // TODO: Check / Uncheck231232 // select / option233 await page.SelectAsync("#continents", "Europe");234235 // input / file236 var file = await page.QuerySelectorAsync("#photo");237 await file.UploadFileAsync(@"c:\temp\test.jpg");238239 // button240 await page.ClickAsync("#submit");241 }242243 [Fact]244 public async Task query()245 {246 var page = await Page();247248 await page.GoToAsync("https://github.com/kblok/puppeteer-sharp");249250 var element = await page.QuerySelectorAsync("h1 > strong > a");251 var elements = await page.QuerySelectorAllAsync("a");252253 Assert.NotNull(element);254 Assert.NotEmpty(elements);255256 var missingElement = await page.QuerySelectorAsync("a#missing-link");257 var missingElements = await page.QuerySelectorAllAsync("a.missing-link");258259 Assert.Null(missingElement);260 Assert.Empty(missingElements);261262 var innerHtml = await element.GetPropertyAsync("innerHTML").Result.JsonValueAsync<string>();263 var outerHtml = await element.GetPropertyAsync("outerHTML").Result.JsonValueAsync<string>();264 var url = await element.GetPropertyAsync("href").Result.JsonValueAsync<string>();265266 Assert.Equal("puppeteer-sharp", innerHtml);267 Assert.Equal("<a data-pjax=\"#js-repo-pjax-container\" href=\"/kblok/puppeteer-sharp\">puppeteer-sharp</a>", outerHtml);268 Assert.Equal("https://github.com/kblok/puppeteer-sharp", url);269270 var innerText = await page.QuerySelectorAsync("h1 > strong > a").EvaluateFunctionAsync<string>("node => node.innerText");271 var outerText = await page.QuerySelectorAsync("h1 > strong > a").EvaluateFunctionAsync<string>("node => node.outerText");272 var textContent = await page.QuerySelectorAsync("h1 > strong > a").EvaluateFunctionAsync<string>("node => node.textContent");273 var hasContent = await page.QuerySelectorAsync("h1 > strong > a").EvaluateFunctionAsync<bool>("(node, value) => node.textContent.includes(value)", "puppeteer-sharp");274275 Assert.Equal("puppeteer-sharp", innerText);276 Assert.Equal("puppeteer-sharp", outerText);277 Assert.Equal("puppeteer-sharp", textContent);278 Assert.True(hasContent);279280 innerHtml = await page.QuerySelectorAsync("h1 > strong > a").EvaluateFunctionAsync<string>("element => element.innerHTML");281 outerHtml = await page.QuerySelectorAsync("h1 > strong > a").EvaluateFunctionAsync<string>("element => element.outerHTML");282 url = await page.QuerySelectorAsync("h1 > strong > a").EvaluateFunctionAsync<string>("element => element.getAttribute('href')");283284 Assert.Equal("puppeteer-sharp", innerHtml);285 Assert.Equal("<a data-pjax=\"#js-repo-pjax-container\" href=\"/kblok/puppeteer-sharp\">puppeteer-sharp</a>", outerHtml);286 Assert.Equal("/kblok/puppeteer-sharp", url);287288 innerText = await page.EvaluateFunctionAsync<string>("node => node.innerText", element);289 outerText = await page.EvaluateFunctionAsync<string>("node => node.outerText", element);290 textContent = await page.EvaluateFunctionAsync<string>("node => node.textContent", element);291292 Assert.Equal("puppeteer-sharp", innerText);293 Assert.Equal("puppeteer-sharp", outerText);294 Assert.Equal("puppeteer-sharp", textContent);295 }296 }*/ ...

Full Screen

Full Screen

Program.cs

Source:Program.cs Github

copy

Full Screen

...14 {15 try16 {17 Thread.Sleep(500); //wait popup18 await _page.QuerySelectorAsync("#privacy__modal__accept").Result.ClickAsync();19 }20 catch (Exception)21 {22 // ignored23 }24 }25 private static async Task Auth()26 {27 var usernameElement = await _page.QuerySelectorAsync(".upc-user-name");28 if (usernameElement != null) return;29 30 #region Get creds31 var credentials = await CredentialsUtils.GetAllAsync();32 string login = credentials["uplay"][0]["login"];33 string password = credentials["uplay"][0]["password"];34 #endregion35 36 await _page.GoToAsync("https://store.ubi.com/ru/account-connection", WaitUntilNavigation.Load);37 #region Get login iframe38 // ReSharper disable StringLiteralTypo39 await _page.WaitForSelectorAsync("#loginiframe", PptrUtils.ShortSelectorAwaiter);40 var accountsFrame = await _page.QuerySelectorAsync("#loginiframe");41 var accountsFrameContent = await accountsFrame.ContentFrameAsync();42 43 await accountsFrameContent.WaitForSelectorAsync("#AuthPassword", PptrUtils.LongSelectorAwaiter);44 #endregion45 #region Fill form46 var loginInput = await accountsFrameContent.QuerySelectorAsync("#AuthEmail");47 if (loginInput is not null) await loginInput.TypeAsync(login);48 var passwordInput = await accountsFrameContent.QuerySelectorAsync("#AuthPassword");49 if (passwordInput is not null) await passwordInput.TypeAsync(password);50 #endregion51 #region Submit52 var submitButton = await accountsFrameContent.QuerySelectorAsync("form button.btn.btn-primary.btn-block");53 await submitButton.ClickAsync();54 #endregion55 }56 57 private static async Task FillTheCart()58 {59 int offset = 0;60 List<string> freeGamesLinks = new();61 while (true)62 {63 string url = $"https://store.ubi.com/ru/games?sz=48&format=page-element&start={offset}";64 await _page.GoToAsync(url, WaitUntilNavigation.Load);65 var products = await _page.QuerySelectorAllAsync("#search-result-items .product-tile");66 if (products.Length == 0) break;67 foreach (ElementHandle product in products)68 {69 var priceElement = await product.QuerySelectorAsync(".price-sales.standard-price");70 if (priceElement == null) return;71 string priceText = await priceElement.EvaluateFunctionAsync<string>("priceElement => priceElement.innerText");72 if (priceText != "0 ₽") continue;73 string href = await product.QuerySelectorAsync("a.thumb-link").Result.EvaluateFunctionAsync<string>("a => a.href");74 freeGamesLinks.Add(href);75 }76 offset += 48;77 }78 foreach (string freeGamesLink in freeGamesLinks)79 {80 await _page.GoToAsync(freeGamesLink, WaitUntilNavigation.Load);81 await _page.QuerySelectorAsync("#add-to-cart").Result.ClickAsync();82 await _page.WaitForSelectorAsync(".giveaway-all-good");83 Console.WriteLine("Added!");84 }85 }86 87 private static async Task GiveawayOnMainPage()88 {89 await _page.GoToAsync("https://store.ubi.com/ru/home", WaitUntilNavigation.Load);90 List<string> freeGamesLinks = new();91 var productTiles = await _page.QuerySelectorAllAsync(".product-tile");92 foreach (var productTile in productTiles)93 {94 var giveawayLabel = await productTile.QuerySelectorAsync(".card-label.giveaway");95 if (giveawayLabel is null) continue;96 var shopButton = await productTile.QuerySelectorAsync("a.shop-now");97 var href = await shopButton.EvaluateFunctionAsync<string>("_ => _.href");98 freeGamesLinks.Add(href);99 }100 foreach (string freeGamesLink in freeGamesLinks)101 {102 await _page.GoToAsync(freeGamesLink, WaitUntilNavigation.Load);103 await _page.QuerySelectorAsync("#add-to-cart").Result.ClickAsync();104 await _page.WaitForSelectorAsync(".giveaway-all-good");105 Console.WriteLine("Added!");106 }107 }108 private static async Task StartBrowser()109 {110 var profilePath = Paths.GetChromiumUserDataDir("ford153focus@gmail.com");111 PptrUtils.ProfilePath = profilePath;112 _page = PptrUtils.Page;113 await _page.GoToAsync("https://store.ubi.com/ru/home", WaitUntilNavigation.Load);114 }115 116 static async Task Main()117 {...

Full Screen

Full Screen

MailRuRegistration.Mail.cs

Source:MailRuRegistration.Mail.cs Github

copy

Full Screen

...10 return @"https://account.mail.ru/login";11 }12 public static async Task<bool> EmailAlreadyRegistered(string accountName, string host, Page page)13 {14 var eAccountName = await page.QuerySelectorAsync("span.b-email__name>input[type='email']");15 if (eAccountName == null) eAccountName = await page.QuerySelectorAsync("input[data-test-id='account__input']");16 await eAccountName.TypeAsync(accountName);17 const string defaultDomain = "mail.ru";18 if (string.IsNullOrEmpty(host)) host = defaultDomain;19 if (!host.ToLower().Equals(defaultDomain))20 {21 //select domain22 var eDomain = await page.QuerySelectorAsync("span.b-email__domain span");23 if (eDomain == null) eDomain = await page.QuerySelectorAsync("div[data-test-id='account__select']");24 await eDomain.ClickAsync();25 var eDomainValue = await page.QuerySelectorAsync($"a[data-text='@{host}']");26 if (eDomainValue == null) eDomainValue = await page.QuerySelectorAsync($"div[data-test-id='select-value:@{host}']");27 await eDomainValue.ClickAsync();28 }29 await page.WaitForTimeoutAsync(1000);30 var altMailExists = await page.QuerySelectorAsync("div.b-tooltip_animate");31 if (altMailExists == null) altMailExists = await page.QuerySelectorAsync("[data-test-id='exists']");32 return altMailExists != null;33 }34 public static async Task<bool> Login(string accountName, string password, Page page)35 {36 //page.EmulateAsync(DeviceDescriptors.Get(DeviceDescriptorName.IPhone6);37 try38 {39 await page.TypeAsync("input[name=Login]", accountName, _typeOptions);40 await page.WaitForTimeoutAsync(500);41 await ClickSubmit(page);42 await page.WaitForTimeoutAsync(500);43 await page.TypeAsync("input[name=Password]", password, _typeOptions);44 await ClickSubmit(page);45 var navigationOptions = new NavigationOptions { WaitUntil = new[] { WaitUntilNavigation.DOMContentLoaded } };46 await page.WaitForNavigationAsync(navigationOptions);47 }48 catch (Exception exception)49 {50 Log.Error(exception);51 return false;52 }53 return true;54 }55 public static async Task<bool> SendEmail(string to, string subject, string[] text, Page page)56 {57 try58 {59 await page.WaitForTimeoutAsync(2000);60 var selNewLetter = "span.compose-button>span>span";61 if (await page.QuerySelectorAsync(selNewLetter) == null) selNewLetter = "a[data-name=compose] span";62 await page.ClickAsync(selNewLetter);63 await page.WaitForTimeoutAsync(1500);64 var selTo = "div[data-type=to] input";65 if (await page.QuerySelectorAsync(selTo) == null) selTo = "div[data-blockid='compose_to']";66 await page.ClickAsync(selTo);67 await page.TypeAsync(selTo, to, _typeOptions);68 var selSubject = "input[name=Subject]";69 //await page.ClickAsync("label[data-for=Subject]") ;70 await page.TypeAsync(selSubject, subject, _typeOptions);71 var selText = "div[role=textbox] div div";72 if (await page.QuerySelectorAsync(selText) == null)73 {74 var elText = await page.QuerySelectorAsync("span.mceEditor iframe");75 var frame = await elText.ContentFrameAsync();76 var elBody = await frame.QuerySelectorAsync("body");77 await elBody.TypeAsync(string.Join(Environment.NewLine, text), _typeOptions);78 }79 else80 {81 await page.ClickAsync(selText);82 await page.TypeAsync(selText, string.Join(Environment.NewLine, text), _typeOptions);83 }84 // or CTRL+ENTER 85 var selSend = "span[data-title-shortcut='Ctrl+Enter']";86 if (await page.QuerySelectorAsync(selSend) == null) selSend = "div[data-name=send]";87 await page.ClickAsync(selSend);88 await page.WaitForNavigationAsync(new NavigationOptions { Timeout = 5000 });89 }90 catch (Exception exception)91 {92 Log.Error(exception);93 return false;94 }95 return true;96 }97 }98}...

Full Screen

Full Screen

AuthIntegrationTests.cs

Source:AuthIntegrationTests.cs Github

copy

Full Screen

...35 {36 var page = await browser.NewPageAsync();37 await page.GoToAsync($"{app.RootUri}signup");38 {39 var emailField = await page.MainFrame.QuerySelectorAsync("#Email");40 await emailField.TypeAsync(Email);41 var passwordField = await page.MainFrame.QuerySelectorAsync("#Password");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

BoundingBoxTests.cs

Source:BoundingBoxTests.cs Github

copy

Full Screen

...17 Width = 500,18 Height = 50019 });20 await Page.GoToAsync(TestConstants.ServerUrl + "/grid.html");21 var elementHandle = await Page.QuerySelectorAsync(".box:nth-of-type(13)");22 var box = await elementHandle.BoundingBoxAsync();23 Assert.Equal(new BoundingBox(100, 50, 50, 50), box);24 }25 [Fact]26 public async Task ShouldHandleNestedFrames()27 {28 await Page.SetViewportAsync(new ViewPortOptions29 {30 Width = 500,31 Height = 50032 });33 await Page.GoToAsync(TestConstants.ServerUrl + "/frames/nested-frames.html");34 var nestedFrame = Page.Frames[1].ChildFrames[1];35 var elementHandle = await nestedFrame.QuerySelectorAsync("div");36 var box = await elementHandle.BoundingBoxAsync();37 Assert.Equal(new BoundingBox(28, 260, 264, 18), box);38 }39 [Fact]40 public async Task ShouldReturnNullForInvisibleElements()41 {42 await Page.SetContentAsync("<div style='display:none'>hi</div>");43 var elementHandle = await Page.QuerySelectorAsync("div");44 Assert.Null(await elementHandle.BoundingBoxAsync());45 }46 }47}...

Full Screen

Full Screen

PuppeteerExtensions.cs

Source:PuppeteerExtensions.cs Github

copy

Full Screen

...16 });17 }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

QuerySelectorAsync

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 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 element = await page.QuerySelectorAsync("input[name=q]");13 await element.TypeAsync("PuppeteerSharp");14 await page.Keyboard.PressAsync("Enter");15 await page.WaitForNavigationAsync();16 Console.WriteLine(await page.TitleAsync());17 }18 }19 }20}

Full Screen

Full Screen

QuerySelectorAsync

Using AI Code Generation

copy

Full Screen

1var browser = await Puppeteer.LaunchAsync(new LaunchOptions2{3 Args = new string[] { "--no-sandbox" }4});5var page = await browser.NewPageAsync();6await page.QuerySelectorAsync("input[name='q']").EvaluateFunctionAsync("element => element.value = 'puppeteer-sharp'");7await page.QuerySelectorAsync("input[name='btnK']").ClickAsync();8var browser = await Puppeteer.LaunchAsync(new LaunchOptions9{10 Args = new string[] { "--no-sandbox" }11});12var page = await browser.NewPageAsync();13await page.QuerySelectorAllAsync("input[name='q']").EvaluateFunctionAsync("element => element.value = 'puppeteer-sharp'");14await page.QuerySelectorAllAsync("input[name='btnK']").ClickAsync();15var browser = await Puppeteer.LaunchAsync(new LaunchOptions16{17 Args = new string[] { "--no-sandbox" }18});19var page = await browser.NewPageAsync();20await page.QuerySelectorAsync("input[name='q']").EvaluateFunctionAsync("element => element.value = 'puppeteer-sharp'");21await page.QuerySelectorAsync("input[name='btnK']").ClickAsync();22var browser = await Puppeteer.LaunchAsync(new LaunchOptions23{24 Args = new string[] { "--no-sandbox" }25});26var page = await browser.NewPageAsync();27await page.QuerySelectorAllAsync("input[name='q']").EvaluateFunctionAsync("element => element.value = 'puppeteer-sharp'");28await page.QuerySelectorAllAsync("input[name='btnK']").ClickAsync();29var browser = await Puppeteer.LaunchAsync(new LaunchOptions30{

Full Screen

Full Screen

QuerySelectorAsync

Using AI Code Generation

copy

Full Screen

1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {8 var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false });9 var page = await browser.NewPageAsync();10 await page.WaitForSelectorAsync("input[title='Search']");11 await page.QuerySelectorAsync("input[title='Search']").EvaluateFunctionAsync("element => element.value = 'PuppeteerSharp'");12 await page.QuerySelectorAsync("input[title='Search']").EvaluateFunctionAsync("element => element.click()");13 await page.WaitForNavigationAsync();14 await page.WaitForSelectorAsync("h3");15 await page.QuerySelectorAsync("h3").EvaluateFunctionAsync("element => element.click()");16 await page.WaitForNavigationAsync();17 await page.WaitForSelectorAsync("body");18 await page.QuerySelectorAsync("body").EvaluateFunctionAsync("element => element.click()");19 await page.WaitForNavigationAsync();20 await page.WaitForSelectorAsync("body");21 await page.QuerySelectorAsync("body").EvaluateFunctionAsync("element => element.click()");22 await page.WaitForNavigationAsync();23 await page.WaitForSelectorAsync("body");24 await page.QuerySelectorAsync("body").EvaluateFunctionAsync("element => element.click()");25 await page.WaitForNavigationAsync();26 await page.WaitForSelectorAsync("body");27 await page.QuerySelectorAsync("body").EvaluateFunctionAsync("element => element.click()");28 await page.WaitForNavigationAsync();29 await page.WaitForSelectorAsync("body");30 await page.QuerySelectorAsync("body").EvaluateFunctionAsync("element => element.click()");31 await page.WaitForNavigationAsync();32 await page.WaitForSelectorAsync("body");33 await page.QuerySelectorAsync("body").EvaluateFunctionAsync("element => element.click()");34 await page.WaitForNavigationAsync();35 await page.WaitForSelectorAsync("body");36 await page.QuerySelectorAsync("body").EvaluateFunctionAsync("element => element.click()");37 await page.WaitForNavigationAsync();38 await page.WaitForSelectorAsync("body");39 await page.QuerySelectorAsync("body").EvaluateFunctionAsync("element => element.click()");40 await page.WaitForNavigationAsync();41 await page.WaitForSelectorAsync("body");42 await page.QuerySelectorAsync("body").EvaluateFunctionAsync("element => element.click()");43 await page.WaitForNavigationAsync();44 await page.WaitForSelectorAsync("

Full Screen

Full Screen

QuerySelectorAsync

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().Wait();9 Console.WriteLine("Press any key to exit.");10 Console.ReadLine();11 }12 static async Task MainAsync()13 {14 var browser = await Puppeteer.LaunchAsync(new LaunchOptions15 {16 ExecutablePath = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"17 });18 var page = await browser.NewPageAsync();19 var element = await page.QuerySelectorAsync("input[name='q']");20 await element.TypeAsync("PuppeteerSharp");21 await page.ScreenshotAsync("google.png");22 await browser.CloseAsync();23 }24 }25}26using System;27using System.Threading.Tasks;28using PuppeteerSharp;29{30 {31 static void Main(string[] args)32 {33 MainAsync().Wait();34 Console.WriteLine("Press any key to exit.");35 Console.ReadLine();36 }37 static async Task MainAsync()38 {39 var browser = await Puppeteer.LaunchAsync(new LaunchOptions40 {41 ExecutablePath = @"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"42 });43 var page = await browser.NewPageAsync();44 var elements = await page.QuerySelectorAllAsync("input[name='q']");45 await elements[0].TypeAsync("PuppeteerSharp");46 await elements[1].TypeAsync("PuppeteerSharp");47 await page.ScreenshotAsync("google.png");48 await browser.CloseAsync();49 }50 }51}52using System;53using System.Threading.Tasks;54using PuppeteerSharp;55{56 {57 static void Main(string[] args)58 {

Full Screen

Full Screen

QuerySelectorAsync

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[title='Search']");13 var element = await page.QuerySelectorAsync("input[title='Search']");14 Console.WriteLine(element);15 await browser.CloseAsync();16 }17 }18}19Method Description AsElementAsync() Returns the ElementHandle as an ElementHandle. ClickAsync() Clicks the element. Dispose() Disposes the ElementHandle. Equals(object obj) Determines whether the specified object is equal to the current object. (Inherited from Object) Finalize() Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) GetHashCode() Serves as the default hash function. (Inherited from Object) GetPropertyAsync(string propertyName) Returns the property value of the element. GetPropertyAsync(string propertyName, object[] args) Returns the property value of the element. GetPropertiesAsync() Returns the properties of the element. GetBoundingBoxAsync() Returns the bounding box of the element. GetElementAsync(string selector) Returns the first element that matches the specified selector. GetElementsAsync(string selector) Returns the first element that matches the specified selector. Get

Full Screen

Full Screen

QuerySelectorAsync

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 options = new LaunchOptions { Headless = true };9 using (var browser = await Puppeteer.LaunchAsync(options))10 using (var page = await browser.NewPageAsync())11 {12 await page.QuerySelectorAsync("input[name='q']");13 }14 }15 }16}17using System;18using System.Threading.Tasks;19using PuppeteerSharp;20{21 {22 static async Task Main(string[] args)23 {24 var options = new LaunchOptions { Headless = true };25 using (var browser = await Puppeteer.LaunchAsync(options))26 using (var page = await browser.NewPageAsync())27 {28 var element = await page.QuerySelectorAsync("input[name='q']");29 Console.WriteLine(element);30 }31 }32 }33}34using System;35using System.Threading.Tasks;36using PuppeteerSharp;37{

Full Screen

Full Screen

QuerySelectorAsync

Using AI Code Generation

copy

Full Screen

1var document = await frame.QuerySelectorAsync("body");2var document = await frame.QuerySelectorAllAsync("body");3var document = await page.QuerySelectorAsync("body");4var document = await page.QuerySelectorAllAsync("body");5var document = await element.QuerySelectorAsync("body");6var document = await element.QuerySelectorAllAsync("body");7var document = await handle.QuerySelectorAsync("body");8var document = await handle.QuerySelectorAllAsync("body");9var document = await frame.QuerySelectorAsync("body");10var document = await frame.QuerySelectorAllAsync("body");11var document = await page.QuerySelectorAsync("body");

Full Screen

Full Screen

QuerySelectorAsync

Using AI Code Generation

copy

Full Screen

1var element = await page.QuerySelectorAsync("input");2Console.WriteLine(await element.EvaluateFunctionAsync<string>("element => element.value"));3Console.WriteLine(await element.EvaluateFunctionAsync<string>("element => element.value"));4Console.WriteLine(await element.EvaluateFunctionAsync<string>("element => element.value"));5Console.WriteLine(await element.EvaluateFunctionAsync<string>("element => element.value"));6var elements = await page.QuerySelectorAllAsync("input");7foreach (var element in elements)8{9 Console.WriteLine(await element.EvaluateFunctionAsync<string>("element => element.value"));10}11foreach (var element in elements)12{13 Console.WriteLine(await element.EvaluateFunctionAsync<string>("element => element.value"));14}15foreach (var element in elements)16{17 Console.WriteLine(await element.EvaluateFunctionAsync<string>("element => element.value"));18}

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