Best Playwright-dotnet code snippet using Microsoft.Playwright.PageQuerySelectorOptions.PageQuerySelectorOptions
PageModel.cs
Source:PageModel.cs
...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);575 }576 protected virtual IRequest WaitForRequest(Regex urlOrPredicate, PageWaitForRequestOptions? options = null)577 {578 return this.Page.WaitForRequest(urlOrPredicate, options);579 }580 protected virtual IRequest WaitForRequest(Func<IRequest, bool> urlOrPredicate, PageWaitForRequestOptions? options = null)581 {582 return this.Page.WaitForRequest(urlOrPredicate, options);583 }584 protected virtual IRequest WaitForRequestFinished(PageWaitForRequestFinishedOptions? options = null)585 {586 return this.Page.WaitForRequestFinished(options);587 }588 protected virtual IResponse WaitForResponse(string urlOrPredicate, PageWaitForResponseOptions? options = null)589 {590 return this.Page.WaitForResponse(urlOrPredicate, options);591 }592 protected virtual IResponse WaitForResponse(Regex urlOrPredicate, PageWaitForResponseOptions? options = null)593 {594 return this.Page.WaitForResponse(urlOrPredicate, options);595 }596 protected virtual IResponse WaitForResponse(Func<IResponse, bool> urlOrPredicate, PageWaitForResponseOptions? options = null)597 {598 return this.Page.WaitForResponse(urlOrPredicate, options);599 }600 protected virtual IResponse RunAndWaitForResponse(Func<Task> action, Func<IResponse, bool> urlOrPredicate, PageRunAndWaitForResponseOptions? options = null)601 {602 return this.Page.RunAndWaitForResponse(action, urlOrPredicate, options);603 }604 protected virtual IElementHandle? WaitForSelector(string selector, PageWaitForSelectorOptions? options = null)605 {606 return this.Page.WaitForSelector(selector, options);607 }608 protected virtual void WaitForTimeout(float timeout)609 {610 this.Page.WaitForTimeout(timeout);611 }612 protected virtual void WaitForURL(Regex url, PageWaitForURLOptions? options = null)613 {614 this.Page.WaitForURL(url, options);615 }616 protected virtual void WaitForURL(Func<string, bool> url, PageWaitForURLOptions? options = null)617 {618 this.Page.WaitForURL(url, options);619 }620 protected virtual IWebSocket WaitForWebSocket(PageWaitForWebSocketOptions? options = null)621 {622 return this.Page.WaitForWebSocket(options);623 }624 protected virtual IWorker WaitForWorker(PageWaitForWorkerOptions? options = null)625 {626 return this.Page.WaitForWorker(options);627 }628 protected virtual IPage? Opener()629 {630 return this.Page.Opener();631 }632 protected virtual void Pause()633 {634 this.Page.Pause();635 }636 protected string GetComputedStyle(637 string selector,638 string styleName,639 PageWaitForSelectorOptions? waitOptions = null,640 PageQuerySelectorOptions? queryOptions = null)641 {642 var element = this.GetElement(selector, waitOptions, queryOptions);643 var styleValue = this.Page.Evaluate<string>($"e => getComputedStyle(e).{styleName}", element);644 return styleValue;645 }646}...
PageAssertions.cs
Source:PageAssertions.cs
...32 }33 private static IElementHandle GetElement(IPage page,34 string selector,35 PageWaitForSelectorOptions? waitOptions = null,36 PageQuerySelectorOptions? queryOptions = null)37 {38 page.WaitForSelector(selector, waitOptions);39 var element = page.QuerySelector(selector, queryOptions)!;40 return element!;41 }42 public static IPage HaveTitle(43 this ReferenceTypeAssertion<IPage> page,44 string expected,45 string because = "no reason given")46 {47 var actual = page.Value.Title();48 if (string.Compare(actual, expected) != 0)49 {50 throw new AssertException(@$"51HaveTitle Assert Exception52Expected:53{expected}54Actual:55{actual}56Because: {because}57");58 }59 return page.Value;60 }61 public static IPage HaveNotTitle(62 this ReferenceTypeAssertion<IPage> page,63 string notExpected,64 string because = "no reason given")65 {66 var actual = page.Value.Title();67 if (string.Compare(actual, notExpected) == 0)68 {69 throw new AssertException(@$"70HaveNotTitle Assert Exception71Not expected:72{notExpected}73Actual:74{actual}75Because:76{because}77");78 }79 return page.Value;80 }81 public static IPage HaveContent(82 this ReferenceTypeAssertion<IPage> page,83 string expected,84 string because = "no reason given")85 {86 var actual = page.Value.Content();87 if (string.Compare(actual, expected) != 0)88 {89 throw new AssertException(@$"90HaveContent Assert Exception91Not expected:92{expected}93Actual:94{actual}95Because:96{because}97");98 }99 return page.Value;100 }101 public static IPage HaveNotContent(102 this ReferenceTypeAssertion<IPage> page,103 string notExpected,104 string because = "no reason given")105 {106 var actual = page.Value.Content();107 if (string.Compare(actual, notExpected) == 0)108 {109 throw new AssertException(@$"110HaveNotContent Assert Exception111Not expected:112{notExpected}113Actual:114{actual}115Because:116{because}117");118 }119 return page.Value;120 }121 public static IPage HaveCheckedElement(122 this ReferenceTypeAssertion<IPage> page,123 string selector,124 string because = "no reason given",125 PageWaitForSelectorOptions? waitOptions = null,126 PageQuerySelectorOptions? queryOptions = null)127 {128 var element = GetElement(page.Value, selector, waitOptions, queryOptions);129 var isChecked = element.IsChecked();130 if (isChecked is false)131 {132 throw new AssertException(@$"133HaveElementChecked Assert Exception134Selector: {selector}135Expected: checked136Actual: not checked137Because: {because}138");139 }140 return page.Value;141 }142 public static IPage HaveNotCheckedElement(143 this ReferenceTypeAssertion<IPage> page,144 string selector,145 string because = "no reason given",146 PageWaitForSelectorOptions? waitOptions = null,147 PageQuerySelectorOptions? queryOptions = null)148 {149 var element = GetElement(page.Value, selector, waitOptions, queryOptions);150 var isChecked = element.IsChecked();151 if (isChecked is true)152 {153 throw new AssertException(@$"154HaveNotElementChecked Assert Exception155Selector: {selector}156Expected: not checked157Actual: checked158Because: {because}159");160 }161 return page.Value;162 }163 public static IPage HaveDisabledElement(164 this ReferenceTypeAssertion<IPage> page,165 string selector,166 string because = "no reason given",167 PageWaitForSelectorOptions? waitOptions = null,168 PageQuerySelectorOptions? queryOptions = null)169 {170 var element = GetElement(page.Value, selector, waitOptions, queryOptions);171 var isDisabled = element.IsDisabled();172 if (isDisabled is false)173 {174 throw new AssertException(@$"175HaveNotElementChecked Assert Exception176Selector: {selector}177Expected: disable178Actual: not disable179Because: {because}180");181 }182 return page.Value;183 }184 public static IPage HaveNotDisabledElement(185 this ReferenceTypeAssertion<IPage> page,186 string selector,187 string because = "no reason given",188 PageWaitForSelectorOptions? waitOptions = null,189 PageQuerySelectorOptions? queryOptions = null)190 {191 var element = GetElement(page.Value, selector, waitOptions, queryOptions);192 var isDisabled = element.IsDisabled();193 if (isDisabled is true)194 {195 throw new AssertException(@$"196HaveNotElementDisabled Assert Exception197Selector: {selector}198Expected: not disable199Actual: disable200Because: {because}201");202 }203 return page.Value;204 }205 public static IPage HaveEditableElement(206 this ReferenceTypeAssertion<IPage> page,207 string selector,208 string because = "no reason given",209 PageWaitForSelectorOptions? waitOptions = null,210 PageQuerySelectorOptions? queryOptions = null)211 {212 var element = GetElement(page.Value, selector, waitOptions, queryOptions);213 var isEditable = element.IsEditable();214 if (isEditable is false)215 {216 throw new AssertException(@$"217HaveElementEditable Assert Exception218Selector: {selector}219Expected: editable220Actual: not editable221Because: {because}222");223 }224 return page.Value;225 }226 public static IPage HaveNotEditableElement(227 this ReferenceTypeAssertion<IPage> page,228 string selector,229 string because = "no reason given",230 PageWaitForSelectorOptions? waitOptions = null,231 PageQuerySelectorOptions? queryOptions = null)232 {233 var element = GetElement(page.Value, selector, waitOptions, queryOptions);234 var isEditable = element.IsEditable();235 if (isEditable is true)236 {237 throw new AssertException(@$"238HaveElementEditable Assert Exception239Selector: {selector}240Expected: not editable241Actual: editable242Because: {because}243");244 }245 return page.Value;246 }247 public static IPage HaveEnabledElement(248 this ReferenceTypeAssertion<IPage> page,249 string selector,250 string because = "no reason given",251 PageWaitForSelectorOptions? waitOptions = null,252 PageQuerySelectorOptions? queryOptions = null)253 {254 var element = GetElement(page.Value, selector, waitOptions, queryOptions);255 var isEnabled = element.IsEnabled();256 if (isEnabled is false)257 {258 throw new AssertException(@$"259HaveElementEnabled Assert Exception260Selector: {selector}261Expected: enable262Actual: not enable263Because: {because}264");265 }266 return page.Value;267 }268 public static IPage HaveNotEnabledElement(269 this ReferenceTypeAssertion<IPage> page,270 string selector,271 string because = "no reason given",272 PageWaitForSelectorOptions? waitOptions = null,273 PageQuerySelectorOptions? queryOptions = null)274 {275 var element = GetElement(page.Value, selector, waitOptions, queryOptions);276 var isEnabled = element.IsEnabled();277 if (isEnabled is true)278 {279 throw new AssertException(@$"280HaveNotElementEnabled Assert Exception281Selector: {selector}282Expected: not enable283Actual: enable284Because: {because}285");286 }287 return page.Value;288 }289 public static IPage HaveHiddenElement(290 this ReferenceTypeAssertion<IPage> page,291 string selector,292 string because = "no reason given",293 PageWaitForSelectorOptions? waitOptions = null,294 PageQuerySelectorOptions? queryOptions = null)295 {296 var element = GetElement(page.Value, selector, waitOptions, queryOptions);297 var isHidden = element.IsHidden();298 if (isHidden is false)299 {300 throw new AssertException(@$"301HaveElementHidden Assert Exception302Selector: {selector}303Expected: hidden304Actual: not hidden305Because: {because}306");307 }308 return page.Value;309 }310 public static IPage HaveNotHiddenElement(311 this ReferenceTypeAssertion<IPage> page,312 string selector,313 string because = "no reason given",314 PageWaitForSelectorOptions? waitOptions = null,315 PageQuerySelectorOptions? queryOptions = null)316 {317 var element = GetElement(page.Value, selector, waitOptions, queryOptions);318 var isHidden = element.IsHidden();319 if (isHidden is true)320 {321 throw new AssertException(@$"322HaveNotElementHidden Assert Exception323Selector: {selector}324Expected: not hidden325Actual: hidden326Because: {because}327");328 }329 return page.Value;330 }331 public static IPage HaveVisibleElement(332 this ReferenceTypeAssertion<IPage> page,333 string selector,334 string because = "no reason given",335 PageWaitForSelectorOptions? waitOptions = null,336 PageQuerySelectorOptions? queryOptions = null)337 {338 var element = GetElement(page.Value, selector, waitOptions, queryOptions);339 var isVisible = element.IsVisible();340 if (isVisible is false)341 {342 throw new AssertException(@$"343HaveElementVisible Assert Exception344Selector: {selector}345Expected: visible346Actual: not visible347Because: {because}348");349 }350 return page.Value;351 }352 public static IPage HaveNotVisibleElement(353 this ReferenceTypeAssertion<IPage> page,354 string selector,355 string because = "no reason given",356 PageWaitForSelectorOptions? waitOptions = null,357 PageQuerySelectorOptions? queryOptions = null)358 {359 var element = GetElement(page.Value, selector, waitOptions, queryOptions);360 var isVisible = element.IsVisible();361 if (isVisible is true)362 {363 throw new AssertException(@$"364HaveElementVisible Assert Exception365Selector: {selector}366Expected: not visible367Actual: visible368Because: {because}369");370 }371 return page.Value;372 }373 public static IPage HaveElementTextContent(374 this ReferenceTypeAssertion<IPage> page,375 string selector,376 string expected,377 string because = "no reason given",378 PageWaitForSelectorOptions? waitOptions = null,379 PageQuerySelectorOptions? queryOptions = null)380 {381 var element = GetElement(page.Value, selector, waitOptions, queryOptions);382 var actual = element.TextContent() ?? "";383 if (string.Compare(actual, expected) != 0)384 {385 throw new AssertException(@$"386HaveElementTextContent Assert Exception387Selector: {selector}388Expected:389{expected}390Actual:391{actual}392Because:393{because}394");395 }396 return page.Value;397 }398 public static IPage HaveNotElementTextContent(399 this ReferenceTypeAssertion<IPage> page,400 string selector,401 string notExpected,402 string because = "no reason given",403 PageWaitForSelectorOptions? waitOptions = null,404 PageQuerySelectorOptions? queryOptions = null)405 {406 var element = GetElement(page.Value, selector, waitOptions, queryOptions);407 var actual = element.TextContent() ?? "";408 if (string.Compare(actual, notExpected) == 0)409 {410 throw new AssertException(@$"411HaveNotElementTextContent Assert Exception412Selector: {selector}413Not expected:414{notExpected}415Actual:416{actual}417Because:418{because}419");420 }421 return page.Value;422 }423 public static IPage HaveElementInnerHTML(424 this ReferenceTypeAssertion<IPage> page,425 string selector,426 string expected,427 string because = "no reason given",428 PageWaitForSelectorOptions? waitOptions = null,429 PageQuerySelectorOptions? queryOptions = null)430 {431 var element = GetElement(page.Value, selector, waitOptions, queryOptions);432 var actual = element.InnerHTML();433 if (string.Compare(actual, expected) != 0)434 {435 throw new AssertException(@$"436HaveElementInnerHTML Assert Exception437Selector: {selector}438Expected:439{expected}440Actual:441{actual}442Because:443{because}444");445 }446 return page.Value;447 }448 public static IPage HaveNotElementInnerHTML(449 this ReferenceTypeAssertion<IPage> page,450 string selector,451 string notExpected,452 string because = "no reason given",453 PageWaitForSelectorOptions? waitOptions = null,454 PageQuerySelectorOptions? queryOptions = null)455 {456 var element = GetElement(page.Value, selector, waitOptions, queryOptions);457 var actual = element.InnerHTML();458 if (string.Compare(actual, notExpected) == 0)459 {460 throw new AssertException(@$"461HaveNotElementInnerHTML Assert Exception462Selector: {selector}463Not expected:464{notExpected}465Actual:466{actual}467Because:468{because}469");470 }471 return page.Value;472 }473 public static IPage HaveElementInnerText(474 this ReferenceTypeAssertion<IPage> page,475 string selector,476 string expected,477 string because = "no reason given",478 PageWaitForSelectorOptions? waitOptions = null,479 PageQuerySelectorOptions? queryOptions = null)480 {481 var element = GetElement(page.Value, selector, waitOptions, queryOptions);482 var actual = element.InnerText();483 if (string.Compare(actual, expected) != 0)484 {485 throw new AssertException(@$"486HaveElementInnerText Assert Exception487Selector: {selector}488Expected:489{expected}490Actual:491{actual}492Because:493{because}494");495 }496 return page.Value;497 }498 public static IPage HaveNotElementInnerText(499 this ReferenceTypeAssertion<IPage> page,500 string selector,501 string notExpected,502 string because = "no reason given",503 PageWaitForSelectorOptions? waitOptions = null,504 PageQuerySelectorOptions? queryOptions = null)505 {506 var element = GetElement(page.Value, selector, waitOptions, queryOptions);507 var actual = element.InnerText();508 if (string.Compare(actual, notExpected) == 0)509 {510 throw new AssertException(@$"511HaveNotElementInnerText Assert Exception512Selector: {selector}513Not expected:514{notExpected}515Actual:516{actual}517Because:518{because}519");520 }521 return page.Value;522 }523 public static IPage HaveElementInputValue(524 this ReferenceTypeAssertion<IPage> page,525 string selector,526 string expected,527 string because = "no reason given",528 PageWaitForSelectorOptions? waitOptions = null,529 PageQuerySelectorOptions? queryOptions = null,530 ElementHandleInputValueOptions? inputOptions = null)531 {532 var element = GetElement(page.Value, selector, waitOptions, queryOptions);533 var actual = element.InputValue(inputOptions);534 if (string.Compare(actual, expected) != 0)535 {536 throw new AssertException(@$"537HaveElementInputValue Assert Exception538Selector: {selector}539Expected:540{expected}541Actual:542{actual}543Because:544{because}545");546 }547 return page.Value;548 }549 public static IPage HaveNotElementInputValue(550 this ReferenceTypeAssertion<IPage> page,551 string selector,552 string notExpected,553 string because = "no reason given",554 PageWaitForSelectorOptions? waitOptions = null,555 PageQuerySelectorOptions? queryOptions = null,556 ElementHandleInputValueOptions? inputOptions = null)557 {558 var element = GetElement(page.Value, selector, waitOptions, queryOptions);559 var actual = element.InputValue(inputOptions);560 if (string.Compare(actual, notExpected) == 0)561 {562 throw new AssertException(@$"563HaveNotElementInputValue Assert Exception564Selector: {selector}565Not expected:566{notExpected}567Actual:568{actual}569Because:570{because}571");572 }573 return page.Value;574 }575 public static IPage HaveElementAttribute(576 this ReferenceTypeAssertion<IPage> page,577 string selector,578 string attributeName,579 string because = "no reason given",580 PageWaitForSelectorOptions? waitOptions = null,581 PageQuerySelectorOptions? queryOptions = null)582 {583 var element = GetElement(page.Value, selector, waitOptions, queryOptions);584 var value = element.GetAttribute(attributeName);585 if (value is null)586 {587 throw new AssertException(@$"588HaveElementAttribute Assert Exception589Selector: {selector}590Expected attribute: {attributeName}591Because: {because}592");593 }594 return page.Value;595 }596 public static IPage HaveNotElementAttribute(597 this ReferenceTypeAssertion<IPage> page,598 string selector,599 string attributeName,600 string because = "no reason given",601 PageWaitForSelectorOptions? waitOptions = null,602 PageQuerySelectorOptions? queryOptions = null)603 {604 var element = GetElement(page.Value, selector, waitOptions, queryOptions);605 var value = element.GetAttribute(attributeName);606 if (value is not null)607 {608 throw new AssertException(@$"609HaveNotElementAttribute Assert Exception610Selector: {selector}611Not expected attribute: {attributeName}612Because: {because}613");614 }615 return page.Value;616 }617 public static IPage HaveElementAttributeValue(618 this ReferenceTypeAssertion<IPage> page,619 string selector,620 string attributeName,621 string expectedAttributeValue,622 string because = "no reason given",623 PageWaitForSelectorOptions? waitOptions = null,624 PageQuerySelectorOptions? queryOptions = null)625 {626 var element = GetElement(page.Value, selector, waitOptions, queryOptions);627 var value = element.GetAttribute(attributeName);628 if (value is null)629 {630 throw new AssertException($"Attribute not found. Attibute name: {attributeName}");631 }632 if (string.Compare(value, expectedAttributeValue) != 0)633 {634 throw new AssertException(@$"635HaveElementAttributeValue Assert Exception636Selector: {selector}637Expected attribute: {attributeName}638Expected attribute value: {expectedAttributeValue}639Actual attribute value: {value}640Because: {because}641");642 }643 return page.Value;644 }645 public static IPage HaveElementNotAttributeValue(646 this ReferenceTypeAssertion<IPage> page,647 string selector,648 string attributeName,649 string expectedAttributeValue,650 string because = "no reason given",651 PageWaitForSelectorOptions? waitOptions = null,652 PageQuerySelectorOptions? queryOptions = null)653 {654 var element = GetElement(page.Value, selector, waitOptions, queryOptions);655 var value = element.GetAttribute(attributeName);656 if (value is null)657 {658 throw new AssertException($"Attribute not found. Attibute name: {attributeName}");659 }660 if (string.Compare(value, expectedAttributeValue) == 0)661 {662 throw new AssertException(@$"663HaveElementNotAttributeValue Assert Exception664Selector: {selector}665Expected attribute: {attributeName}666Not expected attribute value: {expectedAttributeValue}667Actual attribute value: {value}668Because: {because}669");670 }671 return page.Value;672 }673 public static IPage HaveElementComputedStyle(674 this ReferenceTypeAssertion<IPage> page,675 string selector,676 string styleName,677 string expectedStyleValue,678 string because = "no reason given",679 PageWaitForSelectorOptions? waitOptions = null,680 PageQuerySelectorOptions? queryOptions = null)681 {682 var element = GetElement(page.Value, selector, waitOptions, queryOptions);683 var value = element.Evaluate($"e => getComputedStyle(e).{styleName}", element).ToString();684 if (value == "")685 {686 throw new AssertException($"Style not found. Style name: {styleName}");687 }688 if (string.Compare(value, expectedStyleValue) != 0)689 {690 throw new AssertException($@"691HaveElementComputedStyle Assert Exception692Selector: {selector}693Style name: {styleName}694Expected style value: {expectedStyleValue}...
PageDriver.cs
Source:PageDriver.cs
...237 return false;238 }239 }240 /// <inheritdoc cref = "IPage.QuerySelectorAsync" />241 public IElementHandle? QuerySelector(string selector, PageQuerySelectorOptions? options = null)242 {243 return this.AsyncPage.QuerySelectorAsync(selector, options).Result;244 }245 /// <inheritdoc cref = "IPage.WaitForSelectorAsync" />246 public IElementHandle? WaitForSelector(string selector, PageWaitForSelectorOptions? options = null)247 {248 return this.AsyncPage.WaitForSelectorAsync(selector, options).Result;249 }250 /// <inheritdoc cref = "IPage.AddScriptTagAsync" />251 public IElementHandle AddScriptTag(PageAddScriptTagOptions? options = null)252 {253 return this.AsyncPage.AddScriptTagAsync(options).Result;254 }255 /// <inheritdoc cref = "IPage.AddStyleTagAsync" />...
PageModelAssertions.cs
Source:PageModelAssertions.cs
...82 string selector,83 string expectedTextContent,84 string because = "no reason given",85 PageWaitForSelectorOptions? waitOptions = null,86 PageQuerySelectorOptions? queryOptions = null)87 where TPageModel : PageModel88 {89 pageModel.Value.Page.Should().HaveElementTextContent(selector, expectedTextContent, because, waitOptions, queryOptions);90 return pageModel.Value;91 }92 public static TPageModel HaveNotElementTextContent<TPageModel>(93 this ReferenceTypeAssertion<TPageModel> pageModel,94 string selector,95 string notExpectedTextContent,96 string because = "no reason given",97 PageWaitForSelectorOptions? waitOptions = null,98 PageQuerySelectorOptions? queryOptions = null)99 where TPageModel : PageModel100 {101 pageModel.Value.Page.Should().HaveNotElementTextContent(selector, notExpectedTextContent, because, waitOptions, queryOptions);102 return pageModel.Value;103 }104 public static TPageModel HaveElementInnerHTML<TPageModel>(105 this ReferenceTypeAssertion<TPageModel> pageModel,106 string selector,107 string expectedInnerHtml,108 string because = "no reason given",109 PageWaitForSelectorOptions? waitOptions = null,110 PageQuerySelectorOptions? options = null)111 where TPageModel : PageModel112 {113 pageModel.Value.Page.Should().HaveElementInnerHTML(selector, expectedInnerHtml, because, waitOptions, options);114 return pageModel.Value;115 }116 public static TPageModel HaveNotElementInnerHTML<TPageModel>(117 this ReferenceTypeAssertion<TPageModel> pageModel,118 string selector,119 string notExpectedInnerHtml,120 string because = "no reason given",121 PageWaitForSelectorOptions? waitOptions = null,122 PageQuerySelectorOptions? options = null)123 where TPageModel : PageModel124 {125 pageModel.Value.Page.Should().HaveNotElementInnerHTML(selector, notExpectedInnerHtml, because, waitOptions, options);126 return pageModel.Value;127 }128 public static TPageModel HaveElementInnerText<TPageModel>(129 this ReferenceTypeAssertion<TPageModel> pageModel,130 string selector,131 string expectedInnerText,132 string because = "no reason given",133 PageWaitForSelectorOptions? waitOptions = null,134 PageQuerySelectorOptions? options = null)135 where TPageModel : PageModel136 {137 pageModel.Value.Page.Should().HaveElementInnerText(selector, expectedInnerText, because, waitOptions, options);138 return pageModel.Value;139 }140 public static TPageModel HaveNotElementInnerText<TPageModel>(141 this ReferenceTypeAssertion<TPageModel> pageModel,142 string selector,143 string notExpectedInnerText,144 string because = "no reason given",145 PageWaitForSelectorOptions? waitOptions = null,146 PageQuerySelectorOptions? options = null)147 where TPageModel : PageModel148 {149 pageModel.Value.Page.Should().HaveNotElementInnerText(selector, notExpectedInnerText, because, waitOptions, options);150 return pageModel.Value;151 }152 public static TPageModel HaveElementInputValue<TPageModel>(153 this ReferenceTypeAssertion<TPageModel> pageModel,154 string selector,155 string expectedInputValue,156 string because = "no reason given",157 PageWaitForSelectorOptions? waitOptions = null,158 PageQuerySelectorOptions? options = null)159 where TPageModel : PageModel160 {161 pageModel.Value.Page.Should().HaveElementInputValue(selector, expectedInputValue, because, waitOptions, options);162 return pageModel.Value;163 }164 public static TPageModel HaveNotElementInputValue<TPageModel>(165 this ReferenceTypeAssertion<TPageModel> pageModel,166 string selector,167 string notExpectedInputValue,168 string because = "no reason given",169 PageWaitForSelectorOptions? waitOptions = null,170 PageQuerySelectorOptions? options = null)171 where TPageModel : PageModel172 {173 pageModel.Value.Page.Should().HaveNotElementInputValue(selector, notExpectedInputValue, because, waitOptions, options);174 return pageModel.Value;175 }176 public static TPageModel HaveCheckedElement<TPageModel>(177 this ReferenceTypeAssertion<TPageModel> pageModel,178 string selector,179 string because = "no reason given",180 PageWaitForSelectorOptions? waitOptions = null,181 PageQuerySelectorOptions? options = null)182 where TPageModel : PageModel183 {184 pageModel.Value.Page.Should().HaveCheckedElement(selector, because, waitOptions, options);185 return pageModel.Value;186 }187 public static TPageModel HaveNotCheckedElement<TPageModel>(188 this ReferenceTypeAssertion<TPageModel> pageModel,189 string selector,190 string because = "no reason given",191 PageWaitForSelectorOptions? waitOptions = null,192 PageQuerySelectorOptions? options = null)193 where TPageModel : PageModel194 {195 pageModel.Value.Page.Should().HaveNotCheckedElement(selector, because, waitOptions, options);196 return pageModel.Value;197 }198 public static TPageModel HaveDisabledElement<TPageModel>(199 this ReferenceTypeAssertion<TPageModel> pageModel,200 string selector,201 string because = "no reason given",202 PageWaitForSelectorOptions? waitOptions = null,203 PageQuerySelectorOptions? options = null)204 where TPageModel : PageModel205 {206 pageModel.Value.Page.Should().HaveDisabledElement(selector, because, waitOptions, options);207 return pageModel.Value;208 }209 public static TPageModel HaveNotDisabledElement<TPageModel>(210 this ReferenceTypeAssertion<TPageModel> pageModel,211 string selector,212 string because = "no reason given",213 PageWaitForSelectorOptions? waitOptions = null,214 PageQuerySelectorOptions? options = null)215 where TPageModel : PageModel216 {217 pageModel.Value.Page.Should().HaveNotDisabledElement(selector, because, waitOptions, options);218 return pageModel.Value;219 }220 public static TPageModel HaveEditableElement<TPageModel>(221 this ReferenceTypeAssertion<TPageModel> pageModel,222 string selector,223 string because = "no reason given",224 PageWaitForSelectorOptions? waitOptions = null,225 PageQuerySelectorOptions? options = null)226 where TPageModel : PageModel227 {228 pageModel.Value.Page.Should().HaveEditableElement(selector, because, waitOptions, options);229 return pageModel.Value;230 }231 public static TPageModel HaveNotEditableElement<TPageModel>(232 this ReferenceTypeAssertion<TPageModel> pageModel,233 string selector,234 string because = "no reason given",235 PageWaitForSelectorOptions? waitOptions = null,236 PageQuerySelectorOptions? options = null)237 where TPageModel : PageModel238 {239 pageModel.Value.Page.Should().HaveNotEditableElement(selector, because, waitOptions, options);240 return pageModel.Value;241 }242 public static TPageModel HaveEnabledElement<TPageModel>(243 this ReferenceTypeAssertion<TPageModel> pageModel,244 string selector,245 string because = "no reason given",246 PageWaitForSelectorOptions? waitOptions = null,247 PageQuerySelectorOptions? options = null)248 where TPageModel : PageModel249 {250 pageModel.Value.Page.Should().HaveEnabledElement(selector, because, waitOptions, options);251 return pageModel.Value;252 }253 public static TPageModel HaveNotEnabledElement<TPageModel>(254 this ReferenceTypeAssertion<TPageModel> pageModel,255 string selector,256 string because = "no reason given",257 PageWaitForSelectorOptions? waitOptions = null,258 PageQuerySelectorOptions? options = null)259 where TPageModel : PageModel260 {261 pageModel.Value.Page.Should().HaveNotEnabledElement(selector, because, waitOptions, options);262 return pageModel.Value;263 }264 public static TPageModel HaveHiddenElement<TPageModel>(265 this ReferenceTypeAssertion<TPageModel> pageModel,266 string selector,267 string because = "no reason given",268 PageWaitForSelectorOptions? waitOptions = null,269 PageQuerySelectorOptions? options = null)270 where TPageModel : PageModel271 {272 pageModel.Value.Page.Should().HaveHiddenElement(selector, because, waitOptions, options);273 return pageModel.Value;274 }275 public static TPageModel HaveNotHiddenElement<TPageModel>(276 this ReferenceTypeAssertion<TPageModel> pageModel,277 string selector,278 string because = "no reason given",279 PageWaitForSelectorOptions? waitOptions = null,280 PageQuerySelectorOptions? options = null)281 where TPageModel : PageModel282 {283 pageModel.Value.Page.Should().HaveNotHiddenElement(selector, because, waitOptions, options);284 return pageModel.Value;285 }286 public static TPageModel HaveVisibleElement<TPageModel>(287 this ReferenceTypeAssertion<TPageModel> pageModel,288 string selector,289 string because = "no reason given",290 PageWaitForSelectorOptions? waitOptions = null,291 PageQuerySelectorOptions? options = null)292 where TPageModel : PageModel293 {294 pageModel.Value.Page.Should().HaveVisibleElement(selector, because, waitOptions, options);295 return pageModel.Value;296 }297 public static TPageModel HaveNotVisibleElement<TPageModel>(298 this ReferenceTypeAssertion<TPageModel> pageModel,299 string selector,300 string because = "no reason given",301 PageWaitForSelectorOptions? waitOptions = null,302 PageQuerySelectorOptions? options = null)303 where TPageModel : PageModel304 {305 pageModel.Value.Page.Should().HaveNotVisibleElement(selector, because, waitOptions, options);306 return pageModel.Value;307 }308 public static TPageModel HaveElementAttribute<TPageModel>(309 this ReferenceTypeAssertion<TPageModel> pageModel,310 string selector,311 string attributeName,312 string because = "no reason given",313 PageWaitForSelectorOptions? waitOptions = null,314 PageQuerySelectorOptions? options = null)315 where TPageModel : PageModel316 {317 pageModel.Value.Page.Should().HaveElementAttribute(selector, attributeName, because, waitOptions, options);318 return pageModel.Value;319 }320 public static TPageModel HaveElementAttributeValue<TPageModel>(321 this ReferenceTypeAssertion<TPageModel> pageModel,322 string selector,323 string attributeName,324 string expectedValue,325 string because = "no reason given",326 PageWaitForSelectorOptions? waitOptions = null,327 PageQuerySelectorOptions? options = null)328 where TPageModel : PageModel329 {330 pageModel.Value.Page.Should().HaveElementAttributeValue(selector, attributeName, expectedValue, because, waitOptions, options);331 return pageModel.Value;332 }333 public static TPageModel HaveNotElementAttribute<TPageModel>(334 this ReferenceTypeAssertion<TPageModel> pageModel,335 string selector,336 string attributeName,337 string because = "no reason given",338 PageWaitForSelectorOptions? waitOptions = null,339 PageQuerySelectorOptions? options = null)340 where TPageModel : PageModel341 {342 pageModel.Value.Page.Should().HaveNotElementAttribute(selector, attributeName, because, waitOptions, options);343 return pageModel.Value;344 }345 public static TPageModel HaveComputedStyle<TPageModel>(346 this ReferenceTypeAssertion<TPageModel> pageModel,347 string selector,348 string styleName,349 string expectedStyleValue,350 string because = "no reason given",351 PageWaitForSelectorOptions? waitOptions = null,352 PageQuerySelectorOptions? options = null)353 where TPageModel : PageModel354 {355 pageModel.Value.Page.Should().HaveElementComputedStyle(selector, styleName, expectedStyleValue, because, waitOptions, options);356 return pageModel.Value;357 }358}...
PlaywrightHook.cs
Source:PlaywrightHook.cs
...38 public async Task WaitForPage(Regex regex) =>39 await _page.WaitForURLAsync(regex, new PageWaitForURLOptions { Timeout = 0, WaitUntil = WaitUntilState.NetworkIdle });4041 public async Task<bool> IsElementPresent(string xpath) => 42 (await _page.QuerySelectorAsync(xpath, new PageQuerySelectorOptions { })) != null;4344 public async Task<string> GetInnerText(string xpath) =>45 await _page.InnerTextAsync(xpath, new PageInnerTextOptions { });4647 public async ValueTask DisposeAsync()48 {49 await _page.CloseAsync();50 await _browser.DisposeAsync();51 _playwright.Dispose();52 }5354 public async Task Click(string xpath) => 55 await _page.ClickAsync(xpath, new PageClickOptions { });56
...
PageQuerySelectorOptions.cs
Source:PageQuerySelectorOptions.cs
...35using System.Threading.Tasks;36#nullable enable37namespace Microsoft.Playwright38{39 public class PageQuerySelectorOptions40 {41 public PageQuerySelectorOptions() { }42 public PageQuerySelectorOptions(PageQuerySelectorOptions clone)43 {44 if (clone == null)45 {46 return;47 }48 Strict = clone.Strict;49 }50 /// <summary>51 /// <para>52 /// When true, the call requires selector to resolve to a single element. If given selector53 /// resolves to more then one element, the call throws an exception.54 /// </para>55 /// </summary>56 [JsonPropertyName("strict")]...
Menu.cs
Source:Menu.cs
...14 }15 public Menu(ElementModel<TPageModel> parentBlockModel, string selector, ElementHandleWaitForSelectorOptions? waitOptions = null) : base(parentBlockModel, selector, waitOptions)16 {17 }18 public Menu(TPageModel pageModel, string selector, PageWaitForSelectorOptions? waitOptions = null, PageQuerySelectorOptions? queryOptions = null) : base(pageModel, selector, waitOptions, queryOptions)19 {20 }21 public TPageModel ToggleTheme()22 {23 Click(".toggleTrackThumb_xI_Z");24 //WaitForLoadNetworkIdle();25 return PageModel;26 }27 public DocsPage Docs()28 {29 Click("//a[text()='Docs']");30 //WaitForLoadNetworkIdle();31 return new DocsPage(this.Page);32 }...
UIBlock.cs
Source:UIBlock.cs
...11 }12 public UIBlock(ElementModel<TPageModel> parentBlockModel, string selector, ElementHandleWaitForSelectorOptions? waitOptions = null) : base(parentBlockModel, selector, waitOptions)13 {14 }15 public UIBlock(TPageModel pageModel, string selector, PageWaitForSelectorOptions? waitOptions = null, PageQuerySelectorOptions? queryOptions = null) : base(pageModel, selector, waitOptions, queryOptions)16 {17 }18}...
PageQuerySelectorOptions
Using AI Code Generation
1using Microsoft.Playwright;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();7 var page = await browser.NewPageAsync();8 await page.QuerySelectorAsync("input[name='q']", new PageQuerySelectorOptions { State = SelectorState.Attached });9 }10}11using Microsoft.Playwright;12{13 static async Task Main(string[] args)14 {15 using var playwright = await Playwright.CreateAsync();16 await using var browser = await playwright.Chromium.LaunchAsync();17 var page = await browser.NewPageAsync();18 await page.QuerySelectorAsync("input[name='q']", new PageQuerySelectorOptions { State = SelectorState.Visible });19 }20}21using Microsoft.Playwright;22{23 static async Task Main(string[] args)24 {25 using var playwright = await Playwright.CreateAsync();26 await using var browser = await playwright.Chromium.LaunchAsync();27 var page = await browser.NewPageAsync();28 await page.QuerySelectorAsync("input[name='q']", new PageQuerySelectorOptions { State = SelectorState.Hidden });29 }30}31using Microsoft.Playwright;32{33 static async Task Main(string[] args)34 {35 using var playwright = await Playwright.CreateAsync();36 await using var browser = await playwright.Chromium.LaunchAsync();37 var page = await browser.NewPageAsync();38 await page.QuerySelectorAsync("input[name='q']", new PageQuerySelectorOptions { State = SelectorState.Detached });39 }40}41using Microsoft.Playwright;42{
PageQuerySelectorOptions
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using Microsoft.Playwright;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();10 var page = await browser.NewPageAsync();11 var element = await page.QuerySelectorAsync("input[name='q']", new PageQuerySelectorOptions { Force = true });12 Console.WriteLine(element);13 }14 }15}
PageQuerySelectorOptions
Using AI Code Generation
1var playwright = require('playwright');2(async () => {3 for (const browserType of ['chromium', 'firefox', 'webkit']) {4 const browser = await playwright[browserType].launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const element = await page.querySelector('input[type="search"]');8 await element.type('Playwright');9 await element.press('Enter');10 await page.waitForNavigation();11 await page.screenshot({ path: `example-${browserType}.png` });12 await browser.close();13 }14})();
PageQuerySelectorOptions
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Threading.Tasks;4using Microsoft.Playwright;5{6 {7 static async Task Main(string[] args)8 {9 using var playwright = await Playwright.CreateAsync();10 await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions11 {12 });13 var page = await browser.NewPageAsync();14 var element = await page.QuerySelectorAsync("input[name='q']");15 var element2 = await page.QuerySelectorAsync("input[name='q']", new PageQuerySelectorOptions16 {17 });18 await page.ClickAsync("input[name='q']", new PageClickOptions19 {20 {21 },22 });23 await page.ClickAsync("input[name='q']", new PageClickOptions24 {25 {26 },27 });28 await page.ClickAsync("input[name='q']", new PageClickOptions29 {30 {31 },32 });33 await page.ClickAsync("input[name='q']", new PageClickOptions34 {35 {36 },37 });38 await page.ClickAsync("input[name='q']", new PageClickOptions39 {40 {41 },42 });43 await page.ClickAsync("input[name='q']", new PageClickOptions44 {45 {
PageQuerySelectorOptions
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 context = await browser.NewContextAsync();13 var page = await context.NewPageAsync();14 await page.TypeAsync("input[name='q']", "Hello World");15 await page.ClickAsync("input[value='Google Search']");16 await page.WaitForLoadStateAsync(LoadState.NetworkIdle);17 var element = await page.QuerySelectorAsync("div[data-async-context='query:Hello World']");18 var text = await element.EvaluateAsync<string>("el => el.textContent");19 Console.WriteLine(text);20 await context.CloseAsync();21 }22 }23}
PageQuerySelectorOptions
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using Microsoft.Playwright;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();10 var page = await browser.NewPageAsync();11 var searchInput = await page.QuerySelectorAsync("input[name='q']");12 await searchInput.TypeAsync("Hello World!");13 await page.ScreenshotAsync("google.png");14 }15 }16}
PageQuerySelectorOptions
Using AI Code Generation
1using Microsoft.Playwright;2using System.Threading.Tasks;3{4 {5 static async Task Main(string[] args)6 {7 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 var searchBox = await page.QuerySelectorAsync("input[name=q]", new PageQuerySelectorOptions13 {14 });15 await searchBox.TypeAsync("Hello World");16 }17 }18}
PageQuerySelectorOptions
Using AI Code Generation
1using Microsoft.Playwright;2using System.Threading.Tasks;3{4 static async Task Main(string[] args)5 {6 using var playwright = await Playwright.CreateAsync();7 using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions8 {9 });10 var page = await browser.NewPageAsync();11 var element = await page.QuerySelectorAsync("input[name='q']");12 var value = await element.GetAttributeAsync("value");13 System.Console.WriteLine(value);14 }15}
PageQuerySelectorOptions
Using AI Code Generation
1var options = new PageQuerySelectorOptions();2options.Visible = true;3options.Timeout = 1000;4var element = await page.QuerySelectorAsync("div", options);5var options = new PageQuerySelectorOptions();6options.Visible = true;7options.Timeout = 1000;8var element = await page.QuerySelectorAsync("div", options);9var options = new PageQuerySelectorOptions();10options.Visible = true;11options.Timeout = 1000;12var element = await page.QuerySelectorAsync("div", options);13var options = new PageQuerySelectorOptions();14options.Visible = true;15options.Timeout = 1000;16var element = await page.QuerySelectorAsync("div", options);17var options = new PageQuerySelectorOptions();18options.Visible = true;19options.Timeout = 1000;20var element = await page.QuerySelectorAsync("div", options);21var options = new PageQuerySelectorOptions();22options.Visible = true;23options.Timeout = 1000;24var element = await page.QuerySelectorAsync("div", options);25var options = new PageQuerySelectorOptions();26options.Visible = true;27options.Timeout = 1000;28var element = await page.QuerySelectorAsync("div", options);29var options = new PageQuerySelectorOptions();30options.Visible = true;31options.Timeout = 1000;32var element = await page.QuerySelectorAsync("div", options);33var options = new PageQuerySelectorOptions();34options.Visible = true;35 await using var browser = await playwright.Chromium.LaunchAsync();36 var page = await browser.NewPageAsync();37 var searchInput = await page.QuerySelectorAsync("input[name='q']");38 await searchInput.TypeAsync("Hello World!");39 await page.ScreenshotAsync("google.png");40 }41 }42}
PageQuerySelectorOptions
Using AI Code Generation
1using Microsoft.Playwright;2using System.Threading.Tasks;3{4 {5 static async Task Main(string[] args)6 {7 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 var searchBox = await page.QuerySelectorAsync("input[name=q]", new PageQuerySelectorOptions13 {14 });15 await searchBox.TypeAsync("Hello World");16 }17 }18}
PageQuerySelectorOptions
Using AI Code Generation
1using Microsoft.Playwright;2using System.Threading.Tasks;3{4 static async Task Main(string[] args)5 {6 using var playwright = await Playwright.CreateAsync();7 using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions8 {9 });10 var page = await browser.NewPageAsync();11 var element = await page.QuerySelectorAsync("input[name='q']");12 var value = await element.GetAttributeAsync("value");13 System.Console.WriteLine(value);14 }15}
PageQuerySelectorOptions
Using AI Code Generation
1var options = new PageQuerySelectorOptions();2options.Visible = true;3options.Timeout = 1000;4var element = await page.QuerySelectorAsync("div", options);5var options = new PageQuerySelectorOptions();6options.Visible = true;7options.Timeout = 1000;8var element = await page.QuerySelectorAsync("div", options);9var options = new PageQuerySelectorOptions();10options.Visible = true;11options.Timeout = 1000;12var element = await page.QuerySelectorAsync("div", options);13var options = new PageQuerySelectorOptions();14options.Visible = true;15options.Timeout = 1000;16var element = await page.QuerySelectorAsync("div", options);17var options = new PageQuerySelectorOptions();18options.Visible = true;19options.Timeout = 1000;20var element = await page.QuerySelectorAsync("div", options);21var options = new PageQuerySelectorOptions();22options.Visible = true;23options.Timeout = 1000;24var element = await page.QuerySelectorAsync("div", options);25var options = new PageQuerySelectorOptions();26options.Visible = true;27options.Timeout = 1000;28var element = await page.QuerySelectorAsync("div", options);29var options = new PageQuerySelectorOptions();30options.Visible = true;31options.Timeout = 1000;32var element = await page.QuerySelectorAsync("div", options);33var options = new PageQuerySelectorOptions();34options.Visible = true;
PageQuerySelectorOptions
Using AI Code Generation
1using Microsoft.Playwright;2using System.Threading.Tasks;3{4 {5 static async Task Main(string[] args)6 {7 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 var searchBox = await page.QuerySelectorAsync("input[name=q]", new PageQuerySelectorOptions13 {14 });15 await searchBox.TypeAsync("Hello World");16 }17 }18}
PageQuerySelectorOptions
Using AI Code Generation
1using Microsoft.Playwright;2using System.Threading.Tasks;3{4 static async Task Main(string[] args)5 {6 using var playwright = await Playwright.CreateAsync();7 using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions8 {9 });10 var page = await browser.NewPageAsync();11 var element = await page.QuerySelectorAsync("input[name='q']");12 var value = await element.GetAttributeAsync("value");13 System.Console.WriteLine(value);14 }15}
PageQuerySelectorOptions
Using AI Code Generation
1var options = new PageQuerySelectorOptions();2options.Visible = true;3options.Timeout = 1000;4var element = await page.QuerySelectorAsync("div", options);5var options = new PageQuerySelectorOptions();6options.Visible = true;7options.Timeout = 1000;8var element = await page.QuerySelectorAsync("div", options);9var options = new PageQuerySelectorOptions();10options.Visible = true;11options.Timeout = 1000;12var element = await page.QuerySelectorAsync("div", options);13var options = new PageQuerySelectorOptions();14options.Visible = true;15options.Timeout = 1000;16var element = await page.QuerySelectorAsync("div", options);17var options = new PageQuerySelectorOptions();18options.Visible = true;19options.Timeout = 1000;20var element = await page.QuerySelectorAsync("div", options);21var options = new PageQuerySelectorOptions();22options.Visible = true;23options.Timeout = 1000;24var element = await page.QuerySelectorAsync("div", options);25var options = new PageQuerySelectorOptions();26options.Visible = true;27options.Timeout = 1000;28var element = await page.QuerySelectorAsync("div", options);29var options = new PageQuerySelectorOptions();30options.Visible = true;31options.Timeout = 1000;32var element = await page.QuerySelectorAsync("div", options);33var options = new PageQuerySelectorOptions();34options.Visible = true;
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!!