How to use WaitForNavigationAsync method of PuppeteerSharp.Frame class

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

FacebookRegistration.cs

Source:FacebookRegistration.cs Github

copy

Full Screen

...70 await ClickSubmit(page);71 // check phone accepted72 try73 {74 await page.WaitForNavigationAsync();75 }76 catch (Exception exception)77 {78 Log.Debug(exception);79 await _smsService.SetNumberFail(_requestId);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;...

Full Screen

Full Screen

PuppeteerMethods.cs

Source:PuppeteerMethods.cs Github

copy

Full Screen

...146 //You must change your facebook login informations.147 await page.TypeAsync("input#email", username);148 await page.TypeAsync("input#pass", password);149 await page.ClickAsync("button[name='login']");150 await page.WaitForNavigationAsync();151 var HtmlContent = await page.GetContentAsync();152 var Cookie = await page.GetCookiesAsync();153 var TitleOfPage = await page.GetTitleAsync();154 var filePath = "D:\\PdfFiles";155 var fileName = Guid.NewGuid() + ".pdf";156 if (!Directory.Exists(filePath))157 Directory.CreateDirectory(filePath);158 await page.PdfAsync(Path.Combine(filePath, fileName));159 return new SuccessPuppeteerResult("Pdf Created Succesfully");160 }161 catch (Exception ex)162 {163 return new ErrorPuppeteerResult("Error Occured! Detail: " + ex.Message);164 }165 finally166 {167 CloseChromium(page);168 }169 }170 }171 public static async Task<List<string>> VideoLinkList(Page page)172 {173 WaitUntilNavigation[] waitUntil = new[] { WaitUntilNavigation.Networkidle0, WaitUntilNavigation.Networkidle2, WaitUntilNavigation.DOMContentLoaded, WaitUntilNavigation.Load }; 174 var next = @"document.getElementById('pnnext')";175 var nexts = await page.EvaluateExpressionAsync<object>(next);176 var linkList = new List<string>();177 var isLastPage = (nexts == null);178 while ((nexts != null) || !isLastPage)179 {180 var jsSelectAllAnchors = @"Array.from(document.querySelectorAll('.g'))";181 var urls = await page.EvaluateExpressionAsync<object[]>(jsSelectAllAnchors);182 for (int i = 0; i < urls.Length; i++)183 {184 var query = $"document.querySelectorAll('.g')[{i}].getElementsByTagName('a')[0].href";185 linkList.Add(await page.EvaluateExpressionAsync<string>(query));186 }187 nexts = await page.EvaluateExpressionAsync<object>(next);188 if (nexts != null)189 {190 var nextHref = @"document.getElementById('pnnext').href";191 var nextHrefUrl = await page.EvaluateExpressionAsync<string>(nextHref);192 isLastPage = (nexts == null) && !string.IsNullOrEmpty(nextHrefUrl);193 await page.GoToAsync(nextHrefUrl, new NavigationOptions { WaitUntil = waitUntil });194 nexts = await page.EvaluateExpressionAsync<object>(next);195 }196 else197 {198 isLastPage = true;199 }200 }201 return linkList;202 } 203 public static async Task<PuppeteerDataResult<List<string>>> GetVideoSearchVideoResultUrlList(string url, string searchWord)204 {205 using (var page = await OpenChromiumPage())206 {207 WaitUntilNavigation[] waitUntil = new[] { WaitUntilNavigation.Networkidle0, WaitUntilNavigation.Networkidle2, WaitUntilNavigation.DOMContentLoaded, WaitUntilNavigation.Load };208 await page.GoToAsync(url, new NavigationOptions { WaitUntil = waitUntil });209 await SearchOnGoogle(searchWord, page);210 //Click Video Tab211 var videoTabElement = @"document.getElementsByClassName('hdtb-mitem')[4].getElementsByTagName('a')[0].href";212 var videoTabLink = await page.EvaluateExpressionAsync<string>(videoTabElement); 213 await page.GoToAsync(videoTabLink, new NavigationOptions { WaitUntil = waitUntil });214 215 var result= await VideoLinkList(page); 216 return new SuccessPuppeteerDataResult<List<string>>(result, "Get Title Successfully"); 217 }218 }219 public static async Task<PuppeteerDataResult<string>> GetSearchStaticticDetail(string url, string searchWord)220 {221 using (var page = await OpenChromiumPage())222 {223 WaitUntilNavigation[] waitUntil = new[] { WaitUntilNavigation.Networkidle0, WaitUntilNavigation.Networkidle2, WaitUntilNavigation.DOMContentLoaded, WaitUntilNavigation.Load };224 await page.GoToAsync(url, new NavigationOptions { WaitUntil = waitUntil });225 await SearchOnGoogle(searchWord, page);226 var jsExpression = @"document.querySelectorAll('#result-stats')[0].innerHTML";227 var result = await page.EvaluateExpressionAsync<string>(jsExpression);228 return new SuccessPuppeteerDataResult<string>(result, "");229 }230 }231 private static async Task SearchOnGoogle(string searchWord, Page page)232 {233 WaitUntilNavigation[] waitUntil = new[] { WaitUntilNavigation.Networkidle0, WaitUntilNavigation.Networkidle2, WaitUntilNavigation.DOMContentLoaded, WaitUntilNavigation.Load };234 //Search Text Input235 await page.WaitForSelectorAsync("input[name='q']");236 await page.TypeAsync("input[name='q']", searchWord);237 //Search on Google Button and Click Operation238 await page.WaitForSelectorAsync("input[name='btnK']");239 await page.EvaluateExpressionAsync("document.querySelector(\"input[name='btnK']\").click()");240 await page.WaitForNavigationAsync(new NavigationOptions { WaitUntil = waitUntil });241 }242 }243}...

Full Screen

Full Screen

Form1.cs

Source:Form1.cs Github

copy

Full Screen

...113 // await waitElement_ByCssSelector("input[name='password']");114 // await TypeText_ByCssSelector("input[name='password']", "Playhard1@");115 // await waitElement_ByCssSelector("button[type=submit]");116 // await Click_ByCssSelector("button[type=submit]");117 // await page.WaitForNavigationAsync();118 // MessageBox.Show("ok");119 // page.Dialog += (s, e) =>120 // {121 // e.Dialog.Accept();122 // };123 //}124 //public void SwitchMainFrame()125 //{126 // frame = page.MainFrame;127 // usingFrame = false;128 //}129 //public void SwitchFrame(string name, string url = null)130 //{131 // var allFrames = page.Frames;132 // if (string.IsNullOrEmpty(url))133 // frame = allFrames.Where(it => it.Name == name).FirstOrDefault();134 // else135 // frame = allFrames.Where(it => it.Url == url).FirstOrDefault();136 // usingFrame = true;137 //}138 //public async Task<string> GetPageSource()139 //{140 // return await page.GetContentAsync();141 //}142 //public async Task<string> GetFrameSource()143 //{144 // return await frame.GetContentAsync();145 //}146 //public void GoToUrl(string url)147 //{148 // page.GoToAsync(url).Wait();149 //}150 //public async Task WaitForNavigate()151 //{152 // await page.WaitForNavigationAsync();153 //}154 //public async Task FocusElement_ByCssSelector(string selector)155 //{156 // if (usingFrame)157 // await frame.FocusAsync(selector);158 // else159 // await page.FocusAsync(selector);160 //}161 //public async Task TypeText_ByCssSelector(string selector, string val)162 //{163 // if (usingFrame)164 // await frame.TypeAsync(selector, val);165 // else166 // await page.TypeAsync(selector, val);...

Full Screen

Full Screen

PageWaitForNavigationTests.cs

Source:PageWaitForNavigationTests.cs Github

copy

Full Screen

...17 [SkipBrowserFact(skipFirefox: true)]18 public async Task ShouldWork()19 {20 await Page.GoToAsync(TestConstants.EmptyPage);21 var waitForNavigationResult = Page.WaitForNavigationAsync();22 await Task.WhenAll(23 waitForNavigationResult,24 Page.EvaluateFunctionAsync("url => window.location.href = url", TestConstants.ServerUrl + "/grid.html")25 );26 var response = await waitForNavigationResult;27 Assert.Equal(HttpStatusCode.OK, response.Status);28 Assert.Contains("grid.html", response.Url);29 }30 [PuppeteerTest("navigation.spec.ts", "Page.waitForNavigation", "should work with both domcontentloaded and load")]31 [PuppeteerFact]32 public async Task ShouldWorkWithBothDomcontentloadedAndLoad()33 {34 var responseCompleted = new TaskCompletionSource<bool>();35 Server.SetRoute("/one-style.css", _ =>36 {37 return responseCompleted.Task;38 });39 var waitForRequestTask = Server.WaitForRequest("/one-style.css");40 var navigationTask = Page.GoToAsync(TestConstants.ServerUrl + "/one-style.html");41 var domContentLoadedTask = Page.WaitForNavigationAsync(new NavigationOptions42 {43 WaitUntil = new[] { WaitUntilNavigation.DOMContentLoaded }44 });45 var bothFired = false;46 var bothFiredTask = Page.WaitForNavigationAsync(new NavigationOptions47 {48 WaitUntil = new[]49 {50 WaitUntilNavigation.Load,51 WaitUntilNavigation.DOMContentLoaded52 }53 }).ContinueWith(_ => bothFired = true);54 await waitForRequestTask.WithTimeout();55 await domContentLoadedTask.WithTimeout();56 Assert.False(bothFired);57 responseCompleted.SetResult(true);58 await bothFiredTask.WithTimeout();59 await navigationTask.WithTimeout();60 }61 [PuppeteerTest("navigation.spec.ts", "Page.waitForNavigation", "should work with clicking on anchor links")]62 [SkipBrowserFact(skipFirefox: true)]63 public async Task ShouldWorkWithClickingOnAnchorLinks()64 {65 await Page.GoToAsync(TestConstants.EmptyPage);66 await Page.SetContentAsync("<a href='#foobar'>foobar</a>");67 var navigationTask = Page.WaitForNavigationAsync();68 await Task.WhenAll(69 navigationTask,70 Page.ClickAsync("a")71 );72 Assert.Null(await navigationTask);73 Assert.Equal(TestConstants.EmptyPage + "#foobar", Page.Url);74 }75 [PuppeteerTest("navigation.spec.ts", "Page.waitForNavigation", "should work with history.pushState()")]76 [SkipBrowserFact(skipFirefox: true)]77 public async Task ShouldWorkWithHistoryPushState()78 {79 await Page.GoToAsync(TestConstants.EmptyPage);80 await Page.SetContentAsync(@"81 <a onclick='javascript:pushState()'>SPA</a>82 <script>83 function pushState() { history.pushState({}, '', 'wow.html') }84 </script>85 ");86 var navigationTask = Page.WaitForNavigationAsync();87 await Task.WhenAll(88 navigationTask,89 Page.ClickAsync("a")90 );91 Assert.Null(await navigationTask);92 Assert.Equal(TestConstants.ServerUrl + "/wow.html", Page.Url);93 }94 [PuppeteerTest("navigation.spec.ts", "Page.waitForNavigation", "should work with history.replaceState()")]95 [SkipBrowserFact(skipFirefox: true)]96 public async Task ShouldWorkWithHistoryReplaceState()97 {98 await Page.GoToAsync(TestConstants.EmptyPage);99 await Page.SetContentAsync(@"100 <a onclick='javascript:pushState()'>SPA</a>101 <script>102 function pushState() { history.pushState({}, '', 'replaced.html') }103 </script>104 ");105 var navigationTask = Page.WaitForNavigationAsync();106 await Task.WhenAll(107 navigationTask,108 Page.ClickAsync("a")109 );110 Assert.Null(await navigationTask);111 Assert.Equal(TestConstants.ServerUrl + "/replaced.html", Page.Url);112 }113 [PuppeteerTest("navigation.spec.ts", "Page.waitForNavigation", "should work with DOM history.back()/history.forward()")]114 [SkipBrowserFact(skipFirefox: true)]115 public async Task ShouldWorkWithDOMHistoryBackAndHistoryForward()116 {117 await Page.GoToAsync(TestConstants.EmptyPage);118 await Page.SetContentAsync(@"119 <a id=back onclick='javascript:goBack()'>back</a>120 <a id=forward onclick='javascript:goForward()'>forward</a>121 <script>122 function goBack() { history.back(); }123 function goForward() { history.forward(); }124 history.pushState({}, '', '/first.html');125 history.pushState({}, '', '/second.html');126 </script>127 ");128 Assert.Equal(TestConstants.ServerUrl + "/second.html", Page.Url);129 var navigationTask = Page.WaitForNavigationAsync();130 await Task.WhenAll(131 navigationTask,132 Page.ClickAsync("a#back")133 );134 Assert.Null(await navigationTask);135 Assert.Equal(TestConstants.ServerUrl + "/first.html", Page.Url);136 navigationTask = Page.WaitForNavigationAsync();137 await Task.WhenAll(138 navigationTask,139 Page.ClickAsync("a#forward")140 );141 Assert.Null(await navigationTask);142 Assert.Equal(TestConstants.ServerUrl + "/second.html", Page.Url);143 }144 [PuppeteerTest("navigation.spec.ts", "Page.waitForNavigation", "should work when subframe issues window.stop()")]145 [SkipBrowserFact(skipFirefox: true)]146 public async Task ShouldWorkWhenSubframeIssuesWindowStop()147 {148 Server.SetRoute("/frames/style.css", _ => Task.CompletedTask);149 var navigationTask = Page.GoToAsync(TestConstants.ServerUrl + "/frames/one-frame.html");150 var frameAttachedTaskSource = new TaskCompletionSource<Frame>();...

Full Screen

Full Screen

WaitForNavigationTests.cs

Source:WaitForNavigationTests.cs Github

copy

Full Screen

...14 [Fact]15 public async Task ShouldWork()16 {17 await Page.GoToAsync(TestConstants.EmptyPage);18 var waitForNavigationResult = Page.WaitForNavigationAsync();19 await Task.WhenAll(20 waitForNavigationResult,21 Page.EvaluateFunctionAsync("url => window.location.href = url", TestConstants.ServerUrl + "/grid.html")22 );23 var response = await waitForNavigationResult;24 Assert.Equal(HttpStatusCode.OK, response.Status);25 Assert.Contains("grid.html", response.Url);26 }27 [Fact]28 public async Task ShouldWorkWithBothDomcontentloadedAndLoad()29 {30 var responseCompleted = new TaskCompletionSource<bool>();31 Server.SetRoute("/one-style.css", context =>32 {33 return responseCompleted.Task;34 });35 var waitForRequestTask = Server.WaitForRequest("/one-style.css");36 var navigationTask = Page.GoToAsync(TestConstants.ServerUrl + "/one-style.html");37 var domContentLoadedTask = Page.WaitForNavigationAsync(new NavigationOptions38 {39 WaitUntil = new[] { WaitUntilNavigation.DOMContentLoaded }40 });41 var bothFired = false;42 var bothFiredTask = Page.WaitForNavigationAsync(new NavigationOptions43 {44 WaitUntil = new[]45 {46 WaitUntilNavigation.Load,47 WaitUntilNavigation.DOMContentLoaded48 }49 }).ContinueWith(_ => bothFired = true);50 await waitForRequestTask.WithTimeout();51 await domContentLoadedTask.WithTimeout();52 Assert.False(bothFired);53 responseCompleted.SetResult(true);54 await bothFiredTask.WithTimeout();55 await navigationTask.WithTimeout();56 }57 [Fact]58 public async Task ShouldWorkWithClickingOnAnchorLinks()59 {60 await Page.GoToAsync(TestConstants.EmptyPage);61 await Page.SetContentAsync("<a href='#foobar'>foobar</a>");62 var navigationTask = Page.WaitForNavigationAsync();63 await Task.WhenAll(64 navigationTask,65 Page.ClickAsync("a")66 );67 Assert.Null(await navigationTask);68 Assert.Equal(TestConstants.EmptyPage + "#foobar", Page.Url);69 }70 [Fact]71 public async Task ShouldWorkWithHistoryPushState()72 {73 await Page.GoToAsync(TestConstants.EmptyPage);74 await Page.SetContentAsync(@"75 <a onclick='javascript:pushState()'>SPA</a>76 <script>77 function pushState() { history.pushState({}, '', 'wow.html') }78 </script>79 ");80 var navigationTask = Page.WaitForNavigationAsync();81 await Task.WhenAll(82 navigationTask,83 Page.ClickAsync("a")84 );85 Assert.Null(await navigationTask);86 Assert.Equal(TestConstants.ServerUrl + "/wow.html", Page.Url);87 }88 [Fact]89 public async Task ShouldWorkWithHistoryReplaceState()90 {91 await Page.GoToAsync(TestConstants.EmptyPage);92 await Page.SetContentAsync(@"93 <a onclick='javascript:pushState()'>SPA</a>94 <script>95 function pushState() { history.pushState({}, '', 'replaced.html') }96 </script>97 ");98 var navigationTask = Page.WaitForNavigationAsync();99 await Task.WhenAll(100 navigationTask,101 Page.ClickAsync("a")102 );103 Assert.Null(await navigationTask);104 Assert.Equal(TestConstants.ServerUrl + "/replaced.html", Page.Url);105 }106 [Fact]107 public async Task ShouldWorkWithDOMHistoryBackAndHistoryForward()108 {109 await Page.GoToAsync(TestConstants.EmptyPage);110 await Page.SetContentAsync(@"111 <a id=back onclick='javascript:goBack()'>back</a>112 <a id=forward onclick='javascript:goForward()'>forward</a>113 <script>114 function goBack() { history.back(); }115 function goForward() { history.forward(); }116 history.pushState({}, '', '/first.html');117 history.pushState({}, '', '/second.html');118 </script>119 ");120 Assert.Equal(TestConstants.ServerUrl + "/second.html", Page.Url);121 var navigationTask = Page.WaitForNavigationAsync();122 await Task.WhenAll(123 navigationTask,124 Page.ClickAsync("a#back")125 );126 Assert.Null(await navigationTask);127 Assert.Equal(TestConstants.ServerUrl + "/first.html", Page.Url);128 navigationTask = Page.WaitForNavigationAsync();129 await Task.WhenAll(130 navigationTask,131 Page.ClickAsync("a#forward")132 );133 Assert.Null(await navigationTask);134 Assert.Equal(TestConstants.ServerUrl + "/second.html", Page.Url);135 }136 [Fact]137 public async Task ShouldWorkWhenSubframeIssuesWindowStop()138 {139 Server.SetRoute("/frames/style.css", (context) => Task.CompletedTask);140 var navigationTask = Page.GoToAsync(TestConstants.ServerUrl + "/frames/one-frame.html");141 var frameAttachedTaskSource = new TaskCompletionSource<Frame>();142 Page.FrameAttached += (sender, e) =>...

Full Screen

Full Screen

Robot.cs

Source:Robot.cs Github

copy

Full Screen

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

Full Screen

Full Screen

AuthIntegrationTests.cs

Source:AuthIntegrationTests.cs Github

copy

Full Screen

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

FrameWaitForNavigationTests.cs

Source:FrameWaitForNavigationTests.cs Github

copy

Full Screen

...18 public async Task ShouldWork()19 {20 await Page.GoToAsync(TestConstants.ServerUrl + "/frames/one-frame.html");21 var frame = Page.FirstChildFrame();22 var waitForNavigationResult = frame.WaitForNavigationAsync();23 await Task.WhenAll(24 waitForNavigationResult,25 frame.EvaluateFunctionAsync("url => window.location.href = url", TestConstants.ServerUrl + "/grid.html")26 );27 var response = await waitForNavigationResult;28 Assert.Equal(HttpStatusCode.OK, response.Status);29 Assert.Contains("grid.html", response.Url);30 Assert.Same(frame, response.Frame);31 Assert.Contains("/frames/one-frame.html", Page.Url);32 }33 [PuppeteerTest("navigation.spec.ts", "Frame.waitForNavigation", "should fail when frame detaches")]34 [PuppeteerFact]35 public async Task ShouldFailWhenFrameDetaches()36 {37 await Page.GoToAsync(TestConstants.ServerUrl + "/frames/one-frame.html");38 var frame = Page.FirstChildFrame();39 Server.SetRoute("/empty.html", _ => Task.Delay(10000));40 var waitForNavigationResult = frame.WaitForNavigationAsync();41 await Task.WhenAll(42 Server.WaitForRequest("/empty.html"),43 frame.EvaluateFunctionAsync($"() => window.location = '{TestConstants.EmptyPage}'"));44 await Page.QuerySelectorAsync("iframe").EvaluateFunctionAsync("frame => frame.remove()");45 var exception = await Assert.ThrowsAsync<PuppeteerException>(() => waitForNavigationResult);46 Assert.Equal("Navigating frame was detached", exception.Message);47 }48 }49}...

Full Screen

Full Screen

WaitForNavigationAsync

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 var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false });10 var page = await browser.NewPageAsync();11 await page.WaitForSelectorAsync("input[name='q']");12 await page.TypeAsync("input[name='q']", "PuppeteerSharp");13 await page.ClickAsync("input[name='btnK']");14 var frame = await page.WaitForNavigationAsync();15 await page.PdfAsync("google.pdf");16 await browser.CloseAsync();17 }

Full Screen

Full Screen

WaitForNavigationAsync

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 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);10 var browser = await Puppeteer.LaunchAsync(new LaunchOptions11 {12 Args = new string[] { "--start-maximized" }13 });14 var page = await browser.NewPageAsync();15 await page.WaitForNavigationAsync();16 await page.ScreenshotAsync("google.png");17 await browser.CloseAsync();18 }19 }20}21using System;22using System.Threading.Tasks;23using PuppeteerSharp;24{25 {26 static async Task Main(string[] args)27 {28 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);29 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);30 var browser = await Puppeteer.LaunchAsync(new LaunchOptions31 {32 Args = new string[] { "--start-maximized" }33 });34 var page = await browser.NewPageAsync();35 var frame = await page.FrameAsync("frameName");36 await frame.WaitForNavigationAsync();37 await page.ScreenshotAsync("google.png");38 await browser.CloseAsync();39 }40 }41}42using System;43using System.Threading.Tasks;44using PuppeteerSharp;45{46 {47 static async Task Main(string[] args)48 {49 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);

Full Screen

Full Screen

WaitForNavigationAsync

Using AI Code Generation

copy

Full Screen

1using System.Threading.Tasks;2using PuppeteerSharp;3{4 {5 static async Task Main(string[] args)6 {7 {8 };9 using var browser = await Puppeteer.LaunchAsync(options);10 using var page = await browser.NewPageAsync();11 await page.WaitForNavigationAsync();12 await page.ScreenshotAsync("1.png");13 await browser.CloseAsync();14 }15 }16}17using System.Threading.Tasks;18using PuppeteerSharp;19{20 {21 static async Task Main(string[] args)22 {23 {24 };25 using var browser = await Puppeteer.LaunchAsync(options);26 using var page = await browser.NewPageAsync();27 await page.WaitForNavigationAsync();28 await page.ScreenshotAsync("2.png");29 await browser.CloseAsync();30 }31 }32}33using System.Threading.Tasks;34using PuppeteerSharp;35{36 {37 static async Task Main(string[] args)38 {39 {40 };41 using var browser = await Puppeteer.LaunchAsync(options);42 using var page = await browser.NewPageAsync();43 await page.WaitForNavigationAsync(new NavigationOptions { WaitUntil = new[] { WaitUntilNavigation.Networkidle0 } });44 await page.ScreenshotAsync("3.png");45 await browser.CloseAsync();46 }47 }48}49using System.Threading.Tasks;50using PuppeteerSharp;51{52 {53 static async Task Main(string[] args)54 {55 {

Full Screen

Full Screen

WaitForNavigationAsync

Using AI Code Generation

copy

Full Screen

1var frame = await page.GetFrameAsync("frame1");2await frame.WaitForNavigationAsync();3await page.WaitForNavigationAsync();4await page.WaitForNavigationAsync();5var frame = await page.GetFrameAsync("frame1");6await frame.WaitForNavigationAsync();7var frame = await page.GetFrameAsync("frame1");8await frame.WaitForNavigationAsync(new NavigationOptions9{10 WaitUntil = new[] { WaitUntilNavigation.Networkidle0 }11});12var frame = await page.GetFrameAsync("frame1");13await frame.WaitForNavigationAsync(new NavigationOptions14{15 WaitUntil = new[] { WaitUntilNavigation.Networkidle0 },16});17var frame = await page.GetFrameAsync("frame1");18await frame.WaitForNavigationAsync(new NavigationOptions19{20 WaitUntil = new[] { WaitUntilNavigation.Networkidle0 },21});

Full Screen

Full Screen

WaitForNavigationAsync

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 await Task.WhenAll(10 Task.Run(async () =>11 {12 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);13 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }))14 using (var page = await browser.NewPageAsync())15 {16 Console.WriteLine("Page title is: " + await page.EvaluateExpressionAsync<string>("document.title"));17 }18 }),19 Task.Run(async () =>20 {21 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);22 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true }))23 using (var page = await browser.NewPageAsync())24 {25 Console.WriteLine("Page title is: " + await page.EvaluateExpressionAsync<string>("document.title"));26 }27 }));28 }29 }30}

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