Best Playwright-dotnet code snippet using Microsoft.Playwright.PageWaitForLoadStateOptions
Page.cs
Source:Page.cs  
...605        public Task UnrouteAsync(Regex urlString, Action<IRoute> handler)606            => UnrouteAsync(urlString, null, handler);607        public Task UnrouteAsync(Func<string, bool> urlFunc, Action<IRoute> handler)608            => UnrouteAsync(null, urlFunc, handler);609        public Task WaitForLoadStateAsync(LoadState? state = default, PageWaitForLoadStateOptions options = default)610            => MainFrame.WaitForLoadStateAsync(state, new() { Timeout = options?.Timeout });611        public Task SetViewportSizeAsync(int width, int height)612        {613            ViewportSize = new() { Width = width, Height = height };614            return _channel.SetViewportSizeAsync(ViewportSize);615        }616        public Task SetCheckedAsync(string selector, bool checkedState, PageSetCheckedOptions options = null)617            => checkedState ?618            MainFrame.CheckAsync(selector, new()619            {620                Position = options?.Position,621                Force = options?.Force,622                NoWaitAfter = options?.NoWaitAfter,623                Strict = options?.Strict,...BrowserThread.cs
Source:BrowserThread.cs  
...14    {15        //static IPlaywright playwright;16        static IBrowser browser;17        static IBrowserContext context;18        static PageWaitForLoadStateOptions pageWaitOption = new() { Timeout = 60000 };19        static PageWaitForSelectorOptions waitSelectorOptions = new() { Timeout = (60*1000)*60 };20        static PageGotoOptions gotoOptions = new() { Timeout = 60000 };21        static string smshubApiKey = "82349Ue6b7c136067ec23d6b26923401b49a6e";22        static bool stop = false;23        static string proxy;24        static int year;25        static int mo;26        static WebClient webClient = new();27        static Random rnd = new();28        static ViewportSize vSize;29        static int num;30        static string email;31        static string password;32        static string login;...PageModel.cs
Source:PageModel.cs  
...37    }38    protected virtual void Wait() 39    {40    }41    protected virtual void WaitForLoadState(LoadState loadState, PageWaitForLoadStateOptions? options = null)42    {43        this.Page.WaitForLoadState(loadState, options);44    }45    protected TPageModel CreatePageModel<TPageModel>()46        where TPageModel : PageModel47    {48        var ctor = typeof(TPageModel).GetConstructor(new[] { typeof(IPage) });49        if (ctor is null) throw new ApplicationException("Page Model not found");50        var returnPage = ctor.Invoke(new[] { this.Page });51        var page = (TPageModel)returnPage;52        return page;53    }54    protected TBlockModel CreateBlockModel<TBlockModel>(string selector)55        where TBlockModel : class56    {57        var blockType = typeof(TBlockModel);58        var ctorArgs = new[] { this.GetType(), typeof(string) };59        var ctor = blockType.GetConstructor(ctorArgs);60        if (ctor is null) throw new ApplicationException("Block Model not found");61        var block = ctor.Invoke(new[] { this, (object)selector });62        if (block is null) throw new ApplicationException("Block Model not created");63        return (TBlockModel)block;64    }65    protected TBlockModel CreateBlockModel<TBlockModel>(IElementHandle element)66        where TBlockModel : class67    {68        var blockType = typeof(TBlockModel);69        var ctorArgs = new[] { this.GetType(), typeof(IElementHandle) };70        var ctor = blockType.GetConstructor(ctorArgs);71        if (ctor is null) throw new ApplicationException("Block Model not found");72        var block = ctor.Invoke(new[] { this, (object)element });73        if (block is null) throw new ApplicationException("Block Model not created");74        return (TBlockModel)block;75    }76    public virtual TPageModel Goto<TPageModel>(string url, PageGotoOptions? options = null)77        where TPageModel : PageModel78    {79        this.Page.Goto(url, options);80        var page = this.CreatePageModel<TPageModel>();81        return page;82    }83    public virtual TPageModel GoBack<TPageModel>(PageGoBackOptions? options = null)84        where TPageModel : PageModel85    {86        this.Page.GoBack(options);87        var page = this.CreatePageModel<TPageModel>();88        return page;89    }90    public virtual TPageModel GoForward<TPageModel>(PageGoForwardOptions? options = null)91        where TPageModel : PageModel92    {93        this.Page.GoForward(options);94        var page = this.CreatePageModel<TPageModel>();95        return page;96    }97    public virtual TPageModel ReloadToPage<TPageModel>(PageReloadOptions? options = null)98        where TPageModel : PageModel99    {100        this.Page.ReloadAsync(options).GetAwaiter().GetResult();101        var page = this.CreatePageModel<TPageModel>();102        return page;103    }104    public virtual void Close(PageCloseOptions? options = null)105    {106        this.Page.ClosePage(options);107    }108    protected virtual IElementHandle? QuerySelector(string selector, PageQuerySelectorOptions? options = null)109    {110        return this.Page.QuerySelector(selector, options);111    }112    protected virtual IReadOnlyList<IElementHandle> QuerySelectorAll(string selector)113    {114        return this.Page.QuerySelectorAll(selector);115    }116    protected virtual IElementHandle GetElement(117        string selector,118        PageWaitForSelectorOptions? waitOptions = null,119        PageQuerySelectorOptions? queryOptions = null)120    {121        this.Page.WaitForSelector(selector, waitOptions);122        var element = this.Page.QuerySelector(selector, queryOptions);123        return element!;124    }125    protected virtual IReadOnlyCollection<IElementHandle> GetElements(string selector, PageWaitForSelectorOptions? waitOptions = null)126    {127        var elements = this.Page.QuerySelectorAll(selector);128        return elements;129    }130    protected virtual TBlockModel GetElementModel<TBlockModel>(string selector, PageWaitForSelectorOptions? waitOptions = null)131        where TBlockModel : class132    {133        var block = this.CreateBlockModel<TBlockModel>(selector);134        return block;135    }136    protected virtual IReadOnlyCollection<TBlockModel> GetElementModels<TBlockModel>(string selector, PageWaitForSelectorOptions? waitOptions = null)137        where TBlockModel : class138    {139        var elements = this.Page.QuerySelectorAll(selector);140        var blocks = new List<TBlockModel>();141        foreach (var element in elements)142        {143            var block = this.CreateBlockModel<TBlockModel>(element);144            blocks.Add(block);145        }146        return blocks;147    }148    protected virtual IElementHandle? GetElementOrNull(149        string selector,150        PageWaitForSelectorOptions? waitOptions = null,151        PageQuerySelectorOptions? queryOptions = null)152    {153        var element = this.Page.QuerySelector(selector, queryOptions);154        return element;155    }156    protected virtual void Click(string selector, PageClickOptions? options = null)157    {158        this.Page.Click(selector, options);159    }160    protected virtual TReturnPage Click<TReturnPage>(string selector, PageClickOptions? options = null)161        where TReturnPage : PageModel162    {163        this.Click(selector, options);164        var page = this.CreatePageModel<TReturnPage>();165        return page;166    }167    protected virtual void DblClick(string selector, PageDblClickOptions? options = null)168    {169        this.Page.DblClick(selector, options);170    }171    protected virtual void Type(string selector, string value, PageTypeOptions? options = null)172    {173        this.Page.Type(selector, value, options);174    }175    protected virtual void Check(string selector, PageCheckOptions? options = null)176    {177        this.Page.Check(selector, options);178    }179    protected virtual void Uncheck(string selector, PageUncheckOptions? options = null)180    {181        this.Page.Uncheck(selector, options);182    }183    protected virtual void SetChecked(string selector, bool checkedState, PageSetCheckedOptions? options = null)184    {185        this.Page.SetChecked(selector, checkedState, options);186    }187    protected virtual void Tap(string selector, PageTapOptions? options = null)188    {189        this.Page.Tap(selector, options);190    }191    protected virtual void DragAndDrop(string source, string target, PageDragAndDropOptions? options = null)192    {193        this.Page.DragAndDrop(source, target, options);194    }195    protected virtual void Focus(string selector, PageFocusOptions? options = null)196    {197        this.Page.Focus(selector, options);198    }199    protected virtual void Fill(string selector, string value, PageFillOptions? options = null)200    {201        this.Page.Fill(selector, value, options);202    }203    protected virtual void Hover(string selector, PageHoverOptions? options = null)204    {205        this.Page.Hover(selector, options);206    }207    protected virtual void Press(string selector, string key, PagePressOptions? options = null)208    {209        this.Page.Press(selector, key, options);210    }211    protected virtual IReadOnlyList<string> SelectOption(string selector, string values, PageSelectOptionOptions? options = null)212    {213        var result = this.Page.SelectOption(selector, values, options);214        return result;215    }216    protected virtual IReadOnlyList<string> SelectOption(string selector, IElementHandle values, PageSelectOptionOptions? options = null)217    {218        var result = this.Page.SelectOption(selector, values, options);219        return result;220    }221    protected virtual IReadOnlyList<string> SelectOption(string selector, IEnumerable<string> values, PageSelectOptionOptions? options = null)222    {223        var result = this.Page.SelectOption(selector, values, options);224        return result;225    }226    protected virtual IReadOnlyList<string> SelectOption(string selector, SelectOptionValue values, PageSelectOptionOptions? options = null)227    {228        var result = this.Page.SelectOption(selector, values, options);229        return result;230    }231    protected virtual IReadOnlyList<string> SelectOption(string selector, IEnumerable<IElementHandle> values, PageSelectOptionOptions? options = null)232    {233        var result = this.Page.SelectOption(selector, values, options);234        return result;235    }236    protected virtual IReadOnlyList<string> SelectOption(string selector, IEnumerable<SelectOptionValue> values, PageSelectOptionOptions? options = null)237    {238        var result = this.Page.SelectOption(selector, values, options);239        return result;240    }241    protected virtual void SetInputFiles(string selector, string files, PageSetInputFilesOptions? options = null)242    {243        this.Page.SetInputFiles(selector, files, options);244    }245    protected virtual void SetInputFiles(string selector, FilePayload files, PageSetInputFilesOptions? options = null)246    {247        this.Page.SetInputFiles(selector, files, options);248    }249    protected virtual void SetInputFiles(string selector, IEnumerable<string> files, PageSetInputFilesOptions? options = null)250    {251        this.Page.SetInputFiles(selector, files, options);252    }253    protected virtual void SetInputFiles(string selector, IEnumerable<FilePayload> files, PageSetInputFilesOptions? options = null)254    {255        this.Page.SetInputFiles(selector, files, options);256    }257    protected virtual void AddInitScript(string? script = null, string? scriptPath = null)258    {259        this.Page.AddInitScript(script, scriptPath);260    }261    protected virtual void AddScriptTag(PageAddScriptTagOptions? options = null)262    {263        this.Page.AddScriptTag(options);264    }265    protected virtual void AddStyleTag(PageAddStyleTagOptions? options = null)266    {267        this.Page.AddStyleTag(options);268    }269    protected virtual void BringToFront()270    {271        this.Page.BringToFront();272    }273    protected virtual string Content()274    {275        var content = this.Page.Content();276        return content;277    }278    protected virtual void DispatchEvent(string selector, string type, object? eventInit = null, PageDispatchEventOptions? options = null)279    {280        this.Page.DispatchEvent(selector, type, eventInit, options); ;281    }282    protected virtual void EmulateMedia(PageEmulateMediaOptions? options = null)283    {284        this.Page.EmulateMedia(options);285    }286    protected virtual void EvalOnSelectorAll(string selector, string expression, object? arg = null)287    {288        this.Page.EvalOnSelectorAll(selector, expression, arg);289    }290    protected virtual void EvalOnSelectorAll<T>(string selector, string expression, object? arg = null)291    {292        this.Page.EvalOnSelectorAll<T>(selector, expression, arg);293    }294    protected virtual void EvalOnSelector(string selector, string expression, object? arg = null)295    {296        this.Page.EvalOnSelector(selector, expression, arg);297    }298    protected virtual void EvalOnSelector<T>(string selector, string expression, object? arg = null, PageEvalOnSelectorOptions? options = null)299    {300        this.Page.EvalOnSelector<T>(selector, expression, arg, options);301    }302    protected virtual void Evaluate(string expression, object? arg = null)303    {304        this.Page.Evaluate(expression, arg);305    }306    protected virtual void Evaluate<T>(string expression, object? arg = null)307    {308        this.Page.Evaluate<T>(expression, arg);309    }310    protected virtual void EvaluateHandle(string expression, object? arg = null)311    {312        this.Page.EvaluateHandle(expression, arg);313    }314    protected virtual void ExposeBinding(string name, Action<BindingSource> callback)315    {316        this.Page.ExposeBinding(name, callback);317    }318    protected virtual void ExposeBinding(string name, Action callback, PageExposeBindingOptions? options = null)319    {320        this.Page.ExposeBinding(name, callback, options);321    }322    protected virtual void ExposeBinding<T>(string name, Action<BindingSource, T> callback)323    {324        this.Page.ExposeBinding<T>(name, callback);325    }326    protected virtual void ExposeBinding<TResult>(string name, Func<BindingSource, TResult> callback)327    {328        this.Page.ExposeBinding<TResult>(name, callback);329    }330    protected virtual void ExposeBinding<TResult>(string name, Func<BindingSource, IJSHandle, TResult> callback)331    {332        this.Page.ExposeBinding<TResult>(name, callback);333    }334    protected virtual void ExposeBinding<T, TResult>(string name, Func<BindingSource, T, TResult> callback)335    {336        this.Page.ExposeBinding<T, TResult>(name, callback);337    }338    protected virtual void ExposeBinding<T1, T2, TResult>(string name, Func<BindingSource, T1, T2, TResult> callback)339    {340        this.Page.ExposeBinding<T1, T2, TResult>(name, callback);341    }342    protected virtual void ExposeBinding<T1, T2, T3, TResult>(string name, Func<BindingSource, T1, T2, T3, TResult> callback)343    {344        this.Page.ExposeBinding<T1, T2, T3, TResult>(name, callback);345    }346    protected virtual void ExposeBinding<T1, T2, T3, T4, TResult>(string name, Func<BindingSource, T1, T2, T3, T4, TResult> callback)347    {348        this.Page.ExposeBinding<T1, T2, T3, T4, TResult>(name, callback);349    }350    protected virtual void ExposeFunction(string name, Action callback)351    {352        this.Page.ExposeFunction(name, callback);353    }354    protected virtual void ExposeFunction<T>(string name, Action<T> callback)355    {356        this.Page.ExposeFunction<T>(name, callback);357    }358    protected virtual void ExposeFunction<TResult>(string name, Func<TResult> callback)359    {360        this.Page.ExposeFunction<TResult>(name, callback);361    }362    protected virtual void ExposeFunction<T, TResult>(string name, Func<T, TResult> callback)363    {364        this.Page.ExposeFunction<T, TResult>(name, callback);365    }366    protected virtual void ExposeFunction<T1, T2, TResult>(string name, Func<T1, T2, TResult> callback)367    {368        this.Page.ExposeFunction<T1, T2, TResult>(name, callback);369    }370    protected virtual void ExposeFunction<T1, T2, T3, TResult>(string name, Func<T1, T2, T3, TResult> callback)371    {372        this.Page.ExposeFunction<T1, T2, T3, TResult>(name, callback);373    }374    protected virtual void ExposeFunction<T1, T2, T3, T4, TResult>(string name, Func<T1, T2, T3, T4, TResult> callback)375    {376        this.Page.ExposeFunction<T1, T2, T3, T4, TResult>(name, callback);377    }378    protected virtual string? GetAttribute(string selector, string name, PageWaitForSelectorOptions? waitOptions = null, PageGetAttributeOptions? queryOptions = null)379    {380        this.Page.WaitForSelector(selector, waitOptions);381        return this.Page.GetAttribute(selector, name, queryOptions);382    }383    protected virtual string InnerHTML(string selector, PageWaitForSelectorOptions? waitOptions = null, PageInnerHTMLOptions? queryOptions = null)384    {385        this.Page.WaitForSelector(selector, waitOptions);386        return this.Page.InnerHTML(selector, queryOptions);387    }388    protected virtual string InnerText(string selector, PageInnerTextOptions? queryOptions = null)389    {390        return this.Page.InnerText(selector, queryOptions);391    }392    protected virtual string InputValue(string selector, PageInputValueOptions? queryOptions = null)393    {394        return this.Page.InputValue(selector, queryOptions);395    }396    protected virtual bool IsChecked(string selector, PageIsCheckedOptions? queryOptions = null)397    {398        return this.Page.IsChecked(selector, queryOptions);399    }400    protected virtual bool IsDisabled(string selector, PageIsDisabledOptions? options = null)401    {402        return this.Page.IsDisabled(selector, options);403    }404    protected virtual bool IsEditable(string selector, PageIsEditableOptions? options = null)405    {406        return this.Page.IsEditable(selector, options);407    }408    protected virtual bool IsEnabled(string selector, PageIsEnabledOptions? options = null)409    {410        return this.Page.IsEnabled(selector, options);411    }412    protected virtual bool IsHidden(string selector, PageIsHiddenOptions? options = null)413    {414        return this.Page.IsHidden(selector, options);415    }416    protected virtual bool IsVisible(string selector, PageIsVisibleOptions? options = null)417    {418        return this.Page.IsVisible(selector, options);419    }420    protected virtual ILocator IsVisible(string selector)421    {422        return this.Page.Locator(selector);423    }424    protected virtual void Route(string url, Action<IRoute> handler, PageRouteOptions? options = null)425    {426        this.Page.Route(url, handler, options);427    }428    protected virtual void Route(Regex url, Action<IRoute> handler, PageRouteOptions? options = null)429    {430        this.Page.Route(url, handler, options);431    }432    protected virtual void Route(Func<string, bool> url, Action<IRoute> handler, PageRouteOptions? options = null)433    {434        this.Page.Route(url, handler, options);435    }436    protected virtual void Unroute(string url, Action<IRoute>? handler = null)437    {438        this.Page.Unroute(url, handler);439    }440    protected virtual void Unroute(Regex url, Action<IRoute>? handler = null)441    {442        this.Page.Unroute(url, handler);443    }444    protected virtual void Unroute(Func<string, bool> url, Action<IRoute>? handler = null)445    {446        this.Page.Unroute(url, handler);447    }448    protected virtual IFrame? Frame(string name)449    {450        return this.Page.Frame(name);451    }452    protected virtual IFrame? FrameByUrl(string url)453    {454        return this.Page.FrameByUrl(url);455    }456    protected virtual IFrame? FrameByUrl(Regex url)457    {458        return this.Page.FrameByUrl(url);459    }460    protected virtual IFrame? FrameyUrl(Func<string, bool> url)461    {462        return this.Page.FrameByUrl(url);463    }464    protected virtual IConsoleMessage RunAndWaitForConsoleMessage(Func<Task> action, PageRunAndWaitForConsoleMessageOptions? options = null)465    {466        return this.Page.RunAndWaitForConsoleMessage(action, options);467    }468    protected virtual IDownload RunAndWaitForDownload(Func<Task> action, PageRunAndWaitForDownloadOptions? options = null)469    {470        return this.Page.RunAndWaitForDownload(action, options);471    }472    protected virtual IFileChooser RunAndWaitForFileChooser(Func<Task> action, PageRunAndWaitForFileChooserOptions? options = null)473    {474        return this.Page.RunAndWaitForFileChooser(action, options);475    }476    protected virtual IResponse? RunAndWaitForNavigation(Func<Task> action, PageRunAndWaitForNavigationOptions? options = null)477    {478        return this.Page.RunAndWaitForNavigation(action, options);479    }480    protected virtual IPage RunAndWaitForPopup(Func<Task> action, PageRunAndWaitForPopupOptions? options = null)481    {482        return this.Page.RunAndWaitForPopup(action, options);483    }484    protected virtual IRequest RunAndWaitForRequest(Func<Task> action, string urlOrPredicate, PageRunAndWaitForRequestOptions? options = null)485    {486        return this.Page.RunAndWaitForRequest(action, urlOrPredicate, options);487    }488    protected virtual IRequest RunAndWaitForRequest(Func<Task> action, Regex urlOrPredicate, PageRunAndWaitForRequestOptions? options = null)489    {490        return this.Page.RunAndWaitForRequest(action, urlOrPredicate, options);491    }492    protected virtual IRequest RunAndWaitForRequest(Func<Task> action, Func<IRequest, bool> urlOrPredicate, PageRunAndWaitForRequestOptions? options = null)493    {494        return this.Page.RunAndWaitForRequest(action, urlOrPredicate, options);495    }496    protected virtual IRequest RunAndWaitForRequestFinished(Func<Task> action, PageRunAndWaitForRequestFinishedOptions? options = null)497    {498        return this.Page.RunAndWaitForRequestFinished(action, options);499    }500    protected virtual IResponse RunAndWaitForResponse(Func<Task> action, string urlOrPredicate, PageRunAndWaitForResponseOptions? options = null)501    {502        return this.Page.RunAndWaitForResponse(action, urlOrPredicate, options);503    }504    protected virtual IResponse RunAndWaitForResponse(Func<Task> action, Regex urlOrPredicate, PageRunAndWaitForResponseOptions? options = null)505    {506        return this.Page.RunAndWaitForResponse(action, urlOrPredicate, options);507    }508    protected virtual IWebSocket RunAndWaitForWebSocket(Func<Task> action, PageRunAndWaitForWebSocketOptions? options = null)509    {510        return this.Page.RunAndWaitForWebSocket(action, options);511    }512    protected virtual void RunAndWaitForWorker(Func<Task> action, PageRunAndWaitForWorkerOptions? options = null)513    {514        this.Page.RunAndWaitForWorker(action, options);515    }516    protected virtual void Screenshot(PageScreenshotOptions? options = null)517    {518        this.Page.Screenshot(options);519    }520    protected virtual byte[] Pdf(PagePdfOptions? options = null)521    {522        return this.Page.Pdf(options);523    }524    protected virtual void SetContent(string html, PageSetContentOptions? options = null)525    {526        this.Page.SetContent(html, options);527    }528    protected virtual void SetExtraHTTPHeaders(IEnumerable<KeyValuePair<string, string>> headers)529    {530        this.Page.SetExtraHTTPHeaders(headers);531    }532    protected virtual void SetViewportSize(int width, int height)533    {534        this.Page.SetViewportSize(width, height);535    }536    protected virtual string? TextContent(string selector, PageTextContentOptions? options = null)537    {538        return this.Page.TextContent(selector, options);539    }540    protected virtual string Title()541    {542        return this.Page.Title();543    }544    protected virtual IConsoleMessage WaitForConsoleMessage(PageWaitForConsoleMessageOptions? options = null)545    {546        return this.Page.WaitForConsoleMessage(options);547    }548    protected virtual IDownload WaitForDownload(PageWaitForDownloadOptions? options = null)549    {550        return this.Page.WaitForDownload(options);551    }552    protected virtual IFileChooser WaitForFileChooser(PageWaitForFileChooserOptions? options = null)553    {554        return this.Page.WaitForFileChooser(options);555    }556    protected virtual IJSHandle WaitForFunction(string expression, object? arg = null, PageWaitForFunctionOptions? options = null)557    {558        return this.Page.WaitForFunction(expression, arg, options);559    }560    protected virtual void WaitForLoadState(LoadState? state = null, PageWaitForLoadStateOptions? options = null)561    {562        this.Page.WaitForLoadState(state, options);563    }564    protected virtual IResponse? WaitForNavigation(PageWaitForNavigationOptions? options = null)565    {566        return this.Page.WaitForNavigation(options);567    }568    protected virtual IPage WaitForPopup(PageWaitForPopupOptions? options = null)569    {570        return this.Page.WaitForPopup(options);571    }572    protected virtual IRequest WaitForRequest(string urlOrPredicate, PageWaitForRequestOptions? options = null)573    {574        return this.Page.WaitForRequest(urlOrPredicate, options);...PageDriver.cs
Source:PageDriver.cs  
...138        {139            this.AsyncPage.UncheckAsync(selector, options).Wait();140        }141        /// <inheritdoc cref = "IPage.WaitForLoadStateAsync" /> 142        public void WaitForLoadState(LoadState? state = null, PageWaitForLoadStateOptions? options = null)143        {144            this.AsyncPage.WaitForLoadStateAsync(state, options).Wait();145        }146        /// <inheritdoc cref = "IPage.WaitForTimeoutAsync" /> 147        public void WaitForTimeout(float timeout)148        {149            this.AsyncPage.WaitForTimeoutAsync(timeout).Wait();150        }151        /// <inheritdoc cref = "IPage.WaitForURLAsync(Func{string, bool}, PageWaitForURLOptions)" /> 152        public void WaitForURL(Func<string, bool> url, PageWaitForURLOptions? options = null)153        {154            this.AsyncPage.WaitForURLAsync(url, options).Wait();155        }156        /// <inheritdoc cref = "IPage.WaitForURLAsync(Regex, PageWaitForURLOptions)" /> ...Examples.cs
Source:Examples.cs  
...69            var responseTask = page.WaitForResponseAsync("https://github.com/microsoft/playwright-dotnet", new PageWaitForResponseOptions { Timeout = timeout });70            await page.GotoAsync("https://github.com/microsoft/playwright-dotnet");71            await Task.WhenAll(requestTask, responseTask);72            var eventTask = page.WaitForResponseAsync("https://github.com/microsoft/playwright-dotnet");73            var loadStateTask = page.WaitForLoadStateAsync(options: new PageWaitForLoadStateOptions { Timeout = timeout });74            await page.GotoAsync("https://github.com/microsoft/playwright-dotnet");75            await Task.WhenAll(eventTask, loadStateTask);76            await page.ClickAsync("h1 > strong > a");77            await page.WaitForNavigationAsync(new PageWaitForNavigationOptions { Timeout = timeout });78            await page.WaitForFunctionAsync("() => window.location.href === 'https://github.com/microsoft/playwright-dotnet'", timeout);79            await page.WaitForSelectorAsync("#readme", new PageWaitForSelectorOptions { Timeout = timeout });80            await page.WaitForTimeoutAsync(timeout);81            // LoadState82            _ = new[] { LoadState.Load, LoadState.DOMContentLoaded, LoadState.NetworkIdle };83            // WaitForSelectorState84            _ = new[] { WaitForSelectorState.Attached, WaitForSelectorState.Detached, WaitForSelectorState.Visible, WaitForSelectorState.Hidden };85        }86        [Test]87        public async Task values_from_Page()...PlaywrightTest.cs
Source:PlaywrightTest.cs  
...20        using var tester = appHost.NewPlaywrightTester();21        var user = await tester.SignIn(new User("", "it-works")).ConfigureAwait(false);22        var page = await tester.NewPage("chat/the-actual-one").ConfigureAwait(false);23        await page.WaitForLoadStateAsync(LoadState.Load,24            new PageWaitForLoadStateOptions() { Timeout = timeout }).ConfigureAwait(false);25        // TODO: wait for server-side blazor loading, something like page.WaitForWebSocketAsync26        await Task.Delay(2000).ConfigureAwait(false);27        var chatPage = await page.QuerySelectorAsync(".chat-page").ConfigureAwait(false);28        chatPage.Should().NotBeNull();29        var input = await page.QuerySelectorAsync("[role='textbox']").ConfigureAwait(false);30        input.Should().NotBeNull();31        var button = await page.QuerySelectorAsync("button.message-submit").ConfigureAwait(false);32        button.Should().NotBeNull();33        var messages = await GetMessages(page).ConfigureAwait(false);34        var lastMessage = await GetLastMessage(messages).ConfigureAwait(false);35        lastMessage.Should().NotBe("Test-123");36        await input!.TypeAsync("Test-123").ConfigureAwait(false);37        await button!.ClickAsync().ConfigureAwait(false);38        var count = messages.Count;...PageWaitForLoadStateOptions.cs
Source:PageWaitForLoadStateOptions.cs  
...35using System.Threading.Tasks;36#nullable enable37namespace Microsoft.Playwright38{39    public class PageWaitForLoadStateOptions40    {41        public PageWaitForLoadStateOptions() { }42        public PageWaitForLoadStateOptions(PageWaitForLoadStateOptions clone)43        {44            if (clone == null)45            {46                return;47            }48            Timeout = clone.Timeout;49        }50        /// <summary>51        /// <para>52        /// Maximum operation time in milliseconds, defaults to 30 seconds, pass <c>0</c> to53        /// disable timeout. The default value can be changed by using the <see cref="IBrowserContext.SetDefaultNavigationTimeout"/>,54        /// <see cref="IBrowserContext.SetDefaultTimeout"/>, <see cref="IPage.SetDefaultNavigationTimeout"/>55        /// or <see cref="IPage.SetDefaultTimeout"/> methods.56        /// </para>...PlayWrightHtmlLoaderService.cs
Source:PlayWrightHtmlLoaderService.cs  
...28        public async Task<string> GetHtmlBodyAsync(string uri)29        {30            var page = await _browser.NewPageAsync();31            await page.GotoAsync(uri, new PageGotoOptions() { Timeout = 60000 });32            await page.WaitForLoadStateAsync(LoadState.NetworkIdle, new PageWaitForLoadStateOptions() { Timeout = 60000 });33            var htmlContent = await page.ContentAsync();34            await page.CloseAsync();35            return htmlContent;36        }37    }38}...PageWaitForLoadStateOptions
Using AI Code Generation
1var playwright = await Playwright.CreateAsync();2var browser = await playwright.Chromium.LaunchAsync();3var context = await browser.NewContextAsync();4var page = await context.NewPageAsync();5await page.WaitForLoadStateAsync(LoadState.Networkidle);6await page.ScreenshotAsync("google.png");7await browser.CloseAsync();8var playwright = await Playwright.CreateAsync();9var browser = await playwright.Chromium.LaunchAsync();10var context = await browser.NewContextAsync();11var page = await context.NewPageAsync();12await page.WaitForLoadStateAsync(LoadState.Networkidle);13await page.ScreenshotAsync("google.png");14await browser.CloseAsync();15var playwright = await Playwright.CreateAsync();16var browser = await playwright.Chromium.LaunchAsync();17var context = await browser.NewContextAsync();18var page = await context.NewPageAsync();19await page.WaitForLoadStateAsync(LoadState.Networkidle);20await page.ScreenshotAsync("google.png");21await browser.CloseAsync();22var playwright = await Playwright.CreateAsync();23var browser = await playwright.Chromium.LaunchAsync();24var context = await browser.NewContextAsync();25var page = await context.NewPageAsync();26await page.WaitForLoadStateAsync(LoadState.Networkidle);27await page.ScreenshotAsync("google.png");28await browser.CloseAsync();29var playwright = await Playwright.CreateAsync();30var browser = await playwright.Chromium.LaunchAsync();31var context = await browser.NewContextAsync();32var page = await context.NewPageAsync();33await page.WaitForLoadStateAsync(LoadState.Networkidle);34await page.ScreenshotAsync("google.png");35await browser.CloseAsync();PageWaitForLoadStateOptions
Using AI Code Generation
1using Microsoft.Playwright;2using System;3using System.Threading.Tasks;4{5    {6        static async Task Main(string[] args)7        {8            using var playwright = await Playwright.CreateAsync();9            await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions10            {11            });12            var page = await browser.NewPageAsync();13            await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);14            await page.ScreenshotAsync("screenshot.png");15        }16    }17}PageWaitForLoadStateOptions
Using AI Code Generation
1{2    {3        static async Task Main(string[] args)4        {5            using var playwright = await Playwright.CreateAsync();6            await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions7            {8            });9            var page = await browser.NewPageAsync();10            await page.TypeAsync("input[title='Search']", "Hello World");11            await page.ClickAsync("input[value='Google Search']");12            await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);13            Console.WriteLine(await page.GetContentAsync());14        }15    }16}PageWaitForLoadStateOptions
Using AI Code Generation
1PageWaitForLoadStateOptions options = new PageWaitForLoadStateOptions();2options.SetState(LoadState.DOMContentLoaded);3await page.WaitForLoadStateAsync(options);4PageWaitForLoadStateOptions options = new PageWaitForLoadStateOptions();5options.SetState(LoadState.Load);6await page.WaitForLoadStateAsync(options);7PageWaitForLoadStateOptions options = new PageWaitForLoadStateOptions();8options.SetState(LoadState.Networkidle);9await page.WaitForLoadStateAsync(options);10PageWaitForLoadStateOptions options = new PageWaitForLoadStateOptions();11options.SetState(LoadState.DOMContentLoaded);12await page.WaitForLoadStateAsync(options);13PageWaitForLoadStateOptions options = new PageWaitForLoadStateOptions();14options.SetState(LoadState.DOMContentLoaded);15await page.WaitForLoadStateAsync(options);16PageWaitForLoadStateOptions options = new PageWaitForLoadStateOptions();17options.SetState(LoadState.DOMContentLoaded);18await page.WaitForLoadStateAsync(options);19PageWaitForLoadStateOptions options = new PageWaitForLoadStateOptions();20options.SetState(LoadState.DOMContentLoaded);21await page.WaitForLoadStateAsync(options);22PageWaitForLoadStateOptions options = new PageWaitForLoadStateOptions();PageWaitForLoadStateOptions
Using AI Code Generation
1using Microsoft.Playwright;2using System;3using System.Threading.Tasks;4{5    {6        static async Task Main(string[] args)7        {8            using var playwright = await Playwright.CreateAsync();9            await using var browser = await playwright.Chromium.LaunchAsync(new LaunchOptions10            {11            });12            var context = await browser.NewContextAsync();13            var page = await context.NewPageAsync();14            {15            };16            await page.WaitForLoadStateAsync(options);17            await page.ScreenshotAsync("screenshot.png");PageWaitForLoadStateOptions
Using AI Code Generation
1using System.Threading.Tasks;2using Microsoft.Playwright;3{4    {5        static async Task Main(string[] args)6        {7            await using var playwright = await Playwright.CreateAsync();8            await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions9            {10            });11            var page = await browser.NewPageAsync();12            await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);13            await page.ScreenshotAsync("google.png");14        }15    }16}PageWaitForLoadStateOptions
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using Microsoft.Playwright;4{5    {6        static async Task Main(string[] args)7        {8            Console.WriteLine("Hello World!");9            await using var playwright = await Playwright.CreateAsync();10            await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions11            {12            });13            var context = await browser.NewContextAsync();14            var page = await context.NewPageAsync();15            await page.TypeAsync("input[name='q']", "Playwright");16            await page.ClickAsync("text=Google Search");17            await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);18            await page.ScreenshotAsync("example.png");19            await browser.CloseAsync();20        }21    }22}LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!
