Best Playwright-dotnet code snippet using Microsoft.Playwright.Core.Keyboard
FrameChannel.cs
Source:FrameChannel.cs
...238 string selector,239 float? delay,240 MouseButton? button,241 int? clickCount,242 IEnumerable<KeyboardModifier> modifiers,243 Position position,244 float? timeout,245 bool? force,246 bool? noWaitAfter,247 bool? trial,248 bool? strict)249 {250 var args = new Dictionary<string, object>251 {252 ["selector"] = selector,253 ["button"] = button,254 ["force"] = force,255 ["delay"] = delay,256 ["clickCount"] = clickCount,257 ["modifiers"] = modifiers?.Select(m => m.ToValueString()),258 ["position"] = position,259 ["noWaitAfter"] = noWaitAfter,260 ["trial"] = trial,261 ["timeout"] = timeout,262 ["strict"] = strict,263 };264 return Connection.SendMessageToServerAsync<ElementHandleChannel>(Guid, "click", args);265 }266 internal Task DblClickAsync(267 string selector,268 float? delay,269 MouseButton? button,270 Position position,271 IEnumerable<KeyboardModifier> modifiers,272 float? timeout,273 bool? force,274 bool? noWaitAfter,275 bool? trial,276 bool? strict)277 {278 var args = new Dictionary<string, object>279 {280 ["selector"] = selector,281 ["button"] = button,282 ["delay"] = delay,283 ["force"] = force,284 ["modifiers"] = modifiers?.Select(m => m.ToValueString()),285 ["position"] = position,286 ["trial"] = trial,287 ["timeout"] = timeout,288 ["noWaitAfter"] = noWaitAfter,289 ["strict"] = strict,290 };291 return Connection.SendMessageToServerAsync<ElementHandleChannel>(Guid, "dblclick", args);292 }293 internal Task<ElementHandleChannel> QuerySelectorAsync(string selector)294 => Connection.SendMessageToServerAsync<ElementHandleChannel>(295 Guid,296 "querySelector",297 new Dictionary<string, object>298 {299 ["selector"] = selector,300 });301 internal Task<ChannelBase[]> QuerySelectorAllAsync(string selector)302 => Connection.SendMessageToServerAsync<ChannelBase[]>(303 Guid,304 "querySelectorAll",305 new Dictionary<string, object>306 {307 ["selector"] = selector,308 });309 internal Task FillAsync(string selector, string value, bool? force, float? timeout, bool? noWaitAfter, bool? strict)310 {311 var args = new Dictionary<string, object>312 {313 ["selector"] = selector,314 ["value"] = value,315 ["force"] = force,316 ["timeout"] = timeout,317 ["noWaitAfter"] = noWaitAfter,318 ["strict"] = strict,319 };320 return Connection.SendMessageToServerAsync(Guid, "fill", args);321 }322 internal Task CheckAsync(string selector, Position position, float? timeout, bool? force, bool? noWaitAfter, bool? trial, bool? strict)323 {324 var args = new Dictionary<string, object>325 {326 ["selector"] = selector,327 ["force"] = force,328 ["position"] = position,329 ["noWaitAfter"] = noWaitAfter,330 ["trial"] = trial,331 ["timeout"] = timeout,332 ["strict"] = strict,333 };334 return Connection.SendMessageToServerAsync<ElementHandleChannel>(Guid, "check", args);335 }336 internal Task UncheckAsync(string selector, Position position, float? timeout, bool? force, bool? noWaitAfter, bool? trial, bool? strict)337 {338 var args = new Dictionary<string, object>339 {340 ["selector"] = selector,341 ["force"] = force,342 ["position"] = position,343 ["noWaitAfter"] = noWaitAfter,344 ["trial"] = trial,345 ["timeout"] = timeout,346 ["strict"] = strict,347 };348 return Connection.SendMessageToServerAsync<ElementHandleChannel>(Guid, "uncheck", args);349 }350 internal Task DispatchEventAsync(string selector, string type, object eventInit, float? timeout, bool? strict)351 {352 var args = new Dictionary<string, object>353 {354 ["selector"] = selector,355 ["type"] = type,356 ["eventInit"] = eventInit,357 ["timeout"] = timeout,358 ["strict"] = strict,359 };360 return Connection.SendMessageToServerAsync(Guid, "dispatchEvent", args);361 }362 internal Task HoverAsync(363 string selector,364 Position position,365 IEnumerable<KeyboardModifier> modifiers,366 bool? force,367 float? timeout,368 bool? trial,369 bool? strict)370 {371 var args = new Dictionary<string, object>372 {373 ["selector"] = selector,374 ["force"] = force,375 ["modifiers"] = modifiers?.Select(m => m.ToValueString()),376 ["position"] = position,377 ["trial"] = trial,378 ["timeout"] = timeout,379 ["strict"] = strict,380 };381 return Connection.SendMessageToServerAsync(Guid, "hover", args);382 }383 internal Task PressAsync(string selector, string text, float? delay, float? timeout, bool? noWaitAfter, bool? strict)384 {385 var args = new Dictionary<string, object>386 {387 ["selector"] = selector,388 ["key"] = text,389 ["delay"] = delay,390 ["timeout"] = timeout,391 ["noWaitAfter"] = noWaitAfter,392 ["strict"] = strict,393 };394 return Connection.SendMessageToServerAsync(Guid, "press", args);395 }396 internal async Task<string[]> SelectOptionAsync(string selector, IEnumerable<SelectOptionValue> values, bool? noWaitAfter, bool? strict, bool? force, float? timeout)397 {398 var args = new Dictionary<string, object>399 {400 ["selector"] = selector,401 ["options"] = values,402 ["noWaitAfter"] = noWaitAfter,403 ["strict"] = strict,404 ["force"] = force,405 ["timeout"] = timeout,406 };407 return (await Connection.SendMessageToServerAsync(Guid, "selectOption", args).ConfigureAwait(false))?.GetProperty("values").ToObject<string[]>();408 }409 internal async Task<string[]> SelectOptionAsync(string selector, IEnumerable<ElementHandle> values, bool? noWaitAfter, bool? strict, bool? force, float? timeout)410 {411 var args = new Dictionary<string, object>412 {413 ["selector"] = selector,414 ["elements"] = values,415 ["noWaitAfter"] = noWaitAfter,416 ["strict"] = strict,417 ["force"] = force,418 ["timeout"] = timeout,419 };420 return (await Connection.SendMessageToServerAsync(Guid, "selectOption", args).ConfigureAwait(false))?.GetProperty("values").ToObject<string[]>();421 }422 internal async Task<string> GetAttributeAsync(string selector, string name, float? timeout, bool? strict)423 {424 var args = new Dictionary<string, object>425 {426 ["selector"] = selector,427 ["name"] = name,428 ["timeout"] = timeout,429 ["strict"] = strict,430 };431 JsonElement retValue = default;432 if ((await Connection.SendMessageToServerAsync(Guid, "getAttribute", args).ConfigureAwait(false))?.TryGetProperty("value", out retValue) ?? false)433 {434 return retValue.ToString();435 }436 return null;437 }438 internal async Task<string> InnerHTMLAsync(string selector, float? timeout, bool? strict)439 {440 var args = new Dictionary<string, object>441 {442 ["selector"] = selector,443 ["timeout"] = timeout,444 ["strict"] = strict,445 };446 return (await Connection.SendMessageToServerAsync(Guid, "innerHTML", args).ConfigureAwait(false))?.GetProperty("value").ToString();447 }448 internal Task TypeAsync(string selector, string text, float? delay, float? timeout, bool? noWaitAfter, bool? strict)449 {450 var args = new Dictionary<string, object>451 {452 ["selector"] = selector,453 ["text"] = text,454 ["delay"] = delay,455 ["noWaitAfter"] = noWaitAfter,456 ["timeout"] = timeout,457 ["strict"] = strict,458 };459 return Connection.SendMessageToServerAsync(Guid, "type", args);460 }461 internal async Task<string> ContentAsync()462 => (await Connection.SendMessageToServerAsync(463 Guid,464 "content",465 null).ConfigureAwait(false))?.GetProperty("value").ToString();466 internal Task FocusAsync(string selector, float? timeout, bool? strict)467 {468 var args = new Dictionary<string, object>469 {470 ["selector"] = selector,471 ["timeout"] = timeout,472 ["strict"] = strict,473 };474 return Connection.SendMessageToServerAsync(Guid, "focus", args);475 }476 internal async Task<string> InnerTextAsync(string selector, float? timeout, bool? strict)477 {478 var args = new Dictionary<string, object>479 {480 ["selector"] = selector,481 ["timeout"] = timeout,482 ["strict"] = strict,483 };484 return (await Connection.SendMessageToServerAsync(Guid, "innerText", args).ConfigureAwait(false))?.GetProperty("value").ToString();485 }486 internal Task SetInputFilesAsync(string selector, IEnumerable<InputFilesList> files, bool? noWaitAfter, float? timeout, bool? strict)487 {488 var args = new Dictionary<string, object>489 {490 ["selector"] = selector,491 ["files"] = files,492 ["noWaitAfter"] = noWaitAfter,493 ["timeout"] = timeout,494 ["strict"] = strict,495 };496 return Connection.SendMessageToServerAsync(Guid, "setInputFiles", args);497 }498 internal Task SetInputFilePathsAsync(string selector, IEnumerable<string> localPaths, IEnumerable<WritableStream> streams, bool? noWaitAfter, float? timeout, bool? strict)499 {500 var args = new Dictionary<string, object>501 {502 ["selector"] = selector,503 ["localPaths"] = localPaths,504 ["streams"] = streams,505 ["timeout"] = timeout,506 ["noWaitAfter"] = noWaitAfter,507 ["strict"] = strict,508 };509 return Connection.SendMessageToServerAsync(Guid, "setInputFilePaths", args);510 }511 internal async Task<string> TextContentAsync(string selector, float? timeout, bool? strict)512 {513 var args = new Dictionary<string, object>514 {515 ["selector"] = selector,516 ["timeout"] = timeout,517 ["strict"] = strict,518 };519 return (await Connection.SendMessageToServerAsync(Guid, "textContent", args).ConfigureAwait(false))?.GetProperty("value").ToString();520 }521 internal Task TapAsync(522 string selector,523 IEnumerable<KeyboardModifier> modifiers,524 Position position,525 float? timeout,526 bool? force,527 bool? noWaitAfter,528 bool? trial,529 bool? strict)530 {531 var args = new Dictionary<string, object>532 {533 ["selector"] = selector,534 ["force"] = force,535 ["modifiers"] = modifiers?.Select(m => m.ToValueString()),536 ["noWaitAfter"] = noWaitAfter,537 ["trial"] = trial,...
DownloadTests.cs
Source:DownloadTests.cs
...281 await page.SetContentAsync($"<a href=\"{Server.Prefix}/download\">download</a>");282 var downloadTask = page.WaitForDownloadAsync();283 await TaskUtils.WhenAll(284 downloadTask,285 page.ClickAsync("a", new() { Modifiers = new[] { KeyboardModifier.Alt } }));286 var download = downloadTask.Result;287 string path = await download.PathAsync();288 Assert.True(new FileInfo(path).Exists);289 Assert.AreEqual("Hello world", File.ReadAllText(path));290 }291 [PlaywrightTest("download.spec.ts", "should report new window downloads")]292 public async Task ShouldReportNewWindowDownloads()293 {294 var page = await Browser.NewPageAsync(new() { AcceptDownloads = true });295 await page.SetContentAsync($"<a target=_blank href=\"{Server.Prefix}/download\">download</a>");296 var downloadTask = page.WaitForDownloadAsync();297 await TaskUtils.WhenAll(298 downloadTask,299 page.ClickAsync("a"));...
PageChannel.cs
Source:PageChannel.cs
...224 new Dictionary<string, object>225 {226 ["viewportSize"] = viewport,227 });228 internal Task KeyboardDownAsync(string key)229 => Connection.SendMessageToServerAsync(230 Guid,231 "keyboardDown",232 new Dictionary<string, object>233 {234 ["key"] = key,235 });236 internal Task EmulateMediaAsync(Dictionary<string, object> args)237 => Connection.SendMessageToServerAsync(Guid, "emulateMedia", args);238 internal Task KeyboardUpAsync(string key)239 => Connection.SendMessageToServerAsync(240 Guid,241 "keyboardUp",242 new Dictionary<string, object>243 {244 ["key"] = key,245 });246 internal Task TypeAsync(string text, float? delay)247 => Connection.SendMessageToServerAsync(248 Guid,249 "keyboardType",250 new Dictionary<string, object>251 {252 ["text"] = text,...
ElementHandleChannel.cs
Source:ElementHandleChannel.cs
...133 });134 internal Task<FrameChannel> ContentFrameAsync() => Connection.SendMessageToServerAsync<FrameChannel>(Guid, "contentFrame", null);135 internal Task<FrameChannel> OwnerFrameAsync() => Connection.SendMessageToServerAsync<FrameChannel>(Guid, "ownerFrame", null);136 internal Task HoverAsync(137 IEnumerable<KeyboardModifier> modifiers,138 Position position,139 float? timeout,140 bool? force,141 bool? trial)142 {143 var args = new Dictionary<string, object>144 {145 ["force"] = force,146 ["position"] = position,147 ["timeout"] = timeout,148 ["trial"] = trial,149 ["modifiers"] = modifiers?.Select(m => m.ToValueString()),150 };151 return Connection.SendMessageToServerAsync<JsonElement?>(Guid, "hover", args);152 }153 internal Task FocusAsync() => Connection.SendMessageToServerAsync(Guid, "focus", null);154 internal Task ClickAsync(155 float? delay,156 MouseButton? button,157 int? clickCount,158 IEnumerable<KeyboardModifier> modifiers,159 Position position,160 float? timeout,161 bool? force,162 bool? noWaitAfter,163 bool? trial)164 {165 var args = new Dictionary<string, object>166 {167 ["delay"] = delay,168 ["button"] = button,169 ["clickCount"] = clickCount,170 ["force"] = force,171 ["noWaitAfter"] = noWaitAfter,172 ["timeout"] = timeout,173 ["trial"] = trial,174 ["position"] = position,175 ["modifiers"] = modifiers?.Select(m => m.ToValueString()),176 };177 return Connection.SendMessageToServerAsync(Guid, "click", args);178 }179 internal Task DblClickAsync(180 float? delay,181 MouseButton? button,182 IEnumerable<KeyboardModifier> modifiers,183 Position position,184 float? timeout,185 bool? force,186 bool? noWaitAfter,187 bool? trial)188 {189 var args = new Dictionary<string, object>190 {191 ["delay"] = delay,192 ["button"] = button,193 ["force"] = force,194 ["noWaitAfter"] = noWaitAfter,195 ["timeout"] = timeout,196 ["trial"] = trial,197 ["position"] = position,198 ["modifiers"] = modifiers?.Select(m => m.ToValueString()),199 };200 return Connection.SendMessageToServerAsync(Guid, "dblclick", args);201 }202 internal async Task<ElementHandleBoundingBoxResult> BoundingBoxAsync()203 {204 var result = (await Connection.SendMessageToServerAsync(Guid, "boundingBox", null).ConfigureAwait(false)).Value;205 if (result.TryGetProperty("value", out var value))206 {207 return value.ToObject<ElementHandleBoundingBoxResult>();208 }209 return null;210 }211 internal Task ScrollIntoViewIfNeededAsync(float? timeout)212 {213 var args = new Dictionary<string, object>214 {215 ["timeout"] = timeout,216 };217 return Connection.SendMessageToServerAsync<ElementHandleChannel>(Guid, "scrollIntoViewIfNeeded", args);218 }219 internal Task FillAsync(string value, bool? noWaitAfter, bool? force, float? timeout)220 {221 var args = new Dictionary<string, object>222 {223 ["value"] = value,224 ["timeout"] = timeout,225 ["force"] = force,226 ["noWaitAfter"] = noWaitAfter,227 };228 return Connection.SendMessageToServerAsync(Guid, "fill", args);229 }230 internal Task DispatchEventAsync(string type, object eventInit)231 {232 var args = new Dictionary<string, object>233 {234 ["type"] = type,235 ["eventInit"] = eventInit,236 };237 return Connection.SendMessageToServerAsync<ElementHandleChannel>(Guid, "dispatchEvent", args);238 }239 internal Task SetInputFilesAsync(IEnumerable<InputFilesList> files, bool? noWaitAfter, float? timeout)240 {241 var args = new Dictionary<string, object>242 {243 ["files"] = files,244 ["timeout"] = timeout,245 ["noWaitAfter"] = noWaitAfter,246 };247 return Connection.SendMessageToServerAsync(Guid, "setInputFiles", args);248 }249 internal Task SetInputFilePathsAsync(IEnumerable<string> localPaths, IEnumerable<WritableStream> streams, bool? noWaitAfter, float? timeout)250 {251 var args = new Dictionary<string, object>252 {253 ["localPaths"] = localPaths,254 ["streams"] = streams,255 ["timeout"] = timeout,256 ["noWaitAfter"] = noWaitAfter,257 };258 return Connection.SendMessageToServerAsync(Guid, "setInputFilePaths", args);259 }260 internal async Task<string> GetAttributeAsync(string name)261 {262 var args = new Dictionary<string, object>263 {264 ["name"] = name,265 };266 return (await Connection.SendMessageToServerAsync(Guid, "getAttribute", args).ConfigureAwait(false))?.GetProperty("value").ToString();267 }268 internal async Task<string> InnerHTMLAsync()269 => (await Connection.SendMessageToServerAsync(Guid, "innerHTML").ConfigureAwait(false))?.GetProperty("value").ToString();270 internal async Task<string> InnerTextAsync()271 => (await Connection.SendMessageToServerAsync(Guid, "innerText").ConfigureAwait(false))?.GetProperty("value").ToString();272 internal async Task<string> TextContentAsync()273 => (await Connection.SendMessageToServerAsync(Guid, "textContent").ConfigureAwait(false))?.GetProperty("value").ToString();274 internal Task SelectTextAsync(bool? force = null, float? timeout = null)275 {276 var args = new Dictionary<string, object>277 {278 ["force"] = force,279 ["timeout"] = timeout,280 };281 return Connection.SendMessageToServerAsync<ElementHandleChannel>(Guid, "selectText", args);282 }283 internal async Task<IReadOnlyList<string>> SelectOptionAsync(object values, bool? noWaitAfter = null, bool? force = null, float? timeout = null)284 {285 var args = new Dictionary<string, object>();286 if (values is IElementHandle[])287 {288 args["elements"] = values;289 }290 else291 {292 args["options"] = values;293 }294 args["force"] = force;295 args["timeout"] = timeout;296 args["noWaitAfter"] = noWaitAfter;297 return (await Connection.SendMessageToServerAsync(Guid, "selectOption", args).ConfigureAwait(false))?.GetProperty("values").ToObject<List<string>>().AsReadOnly();298 }299 internal async Task<bool> IsVisibleAsync()300 => (await Connection.SendMessageToServerAsync(Guid, "isVisible", null).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default;301 internal async Task<bool> IsHiddenAsync()302 => (await Connection.SendMessageToServerAsync(Guid, "isHidden", null).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default;303 internal async Task<bool> IsEnabledAsync()304 => (await Connection.SendMessageToServerAsync(Guid, "isEnabled", null).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default;305 internal async Task<bool> IsEditableAsync()306 => (await Connection.SendMessageToServerAsync(Guid, "isEditable", null).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default;307 internal async Task<bool> IsDisabledAsync()308 => (await Connection.SendMessageToServerAsync(Guid, "isDisabled", null).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default;309 internal async Task<string> InputValueAsync(float? timeout)310 {311 var args = new Dictionary<string, object>()312 {313 { "timeout", timeout },314 };315 return (await Connection.SendMessageToServerAsync(Guid, "inputValue", args).ConfigureAwait(false))?.GetProperty("value").GetString();316 }317 internal async Task<bool> IsCheckedAsync()318 => (await Connection.SendMessageToServerAsync(Guid, "isChecked", null).ConfigureAwait(false))?.GetProperty("value").GetBoolean() ?? default;319 internal Task CheckAsync(Position position, float? timeout, bool? force, bool? noWaitAfter, bool? trial)320 {321 var args = new Dictionary<string, object>322 {323 ["force"] = force,324 ["position"] = position,325 ["trial"] = trial,326 ["timeout"] = timeout,327 ["noWaitAfter"] = noWaitAfter,328 };329 return Connection.SendMessageToServerAsync<ElementHandleChannel>(Guid, "check", args);330 }331 internal Task UncheckAsync(Position position, float? timeout, bool? force, bool? noWaitAfter, bool? trial)332 {333 var args = new Dictionary<string, object>334 {335 ["force"] = force,336 ["position"] = position,337 ["trial"] = trial,338 ["timeout"] = timeout,339 ["noWaitAfter"] = noWaitAfter,340 };341 return Connection.SendMessageToServerAsync<ElementHandleChannel>(Guid, "uncheck", args);342 }343 internal Task TypeAsync(string text, float? delay, float? timeout, bool? noWaitAfter)344 {345 var args = new Dictionary<string, object>346 {347 ["text"] = text,348 ["delay"] = delay,349 ["timeout"] = timeout,350 ["noWaitAfter"] = noWaitAfter,351 };352 return Connection.SendMessageToServerAsync(Guid, "type", args);353 }354 internal Task PressAsync(string key, float? delay, float? timeout, bool? noWaitAfter)355 {356 var args = new Dictionary<string, object>357 {358 ["key"] = key,359 ["delay"] = delay,360 ["timeout"] = timeout,361 ["noWaitAfter"] = noWaitAfter,362 };363 return Connection.SendMessageToServerAsync(Guid, "press", args);364 }365 internal Task TapAsync(366 Position position,367 IEnumerable<KeyboardModifier> modifiers,368 float? timeout,369 bool? force,370 bool? noWaitAfter,371 bool? trial)372 {373 var args = new Dictionary<string, object>374 {375 ["force"] = force,376 ["noWaitAfter"] = noWaitAfter,377 ["position"] = position,378 ["modifiers"] = modifiers?.Select(m => m.ToValueString()),379 ["trial"] = trial,380 ["timeout"] = timeout,381 };...
PlaywrightIPhoneTest.cs
Source:PlaywrightIPhoneTest.cs
...23 try {24 await page.GotoAsync("https://www.google.co.in/");25 await page.Locator("[aria-label='Search']").ClickAsync();26 await page.FillAsync("[aria-label='Search']", "BrowserStack");27 await page.Keyboard.PressAsync("Enter");28 await page.Locator("[aria-current='page']").WaitForAsync();29 var title = await page.TitleAsync();30 if (title == "BrowserStack - Google Search")31 {32 // following line of code is responsible for marking the status of the test on BrowserStack as 'passed'. You can use this code in your after hook after each test33 await MarkTestStatus("passed", "Title matched", page);34 } else {35 await MarkTestStatus("failed", "Title did not match", page);36 }37 }38 catch (Exception err) {39 await MarkTestStatus("failed", err.Message, page);40 }41 await browser.CloseAsync();...
PlaywrightPixelTest.cs
Source:PlaywrightPixelTest.cs
...23 try {24 await page.GotoAsync("https://www.google.co.in/");25 await page.Locator("[aria-label='Search']").ClickAsync();26 await page.FillAsync("[aria-label='Search']", "BrowserStack");27 await page.Keyboard.PressAsync("Enter");28 await page.Locator("[aria-current='page']").WaitForAsync();29 var title = await page.TitleAsync();30 if (title == "BrowserStack - Google Search")31 {32 // following line of code is responsible for marking the status of the test on BrowserStack as 'passed'. You can use this code in your after hook after each test33 await MarkTestStatus("passed", "Title matched", page);34 } else {35 await MarkTestStatus("failed", "Title did not match", page);36 }37 }38 catch (Exception err) {39 await MarkTestStatus("failed", err.Message, page);40 }41 await browser.CloseAsync();...
SearchTests.cs
Source:SearchTests.cs
...50 await element.ClickAsync();51 }52 // Search for the desired term53 await page.TypeAsync("[name='q']", ".net core");54 await page.Keyboard.PressAsync("Enter");55 // Wait for the results to load56 await page.WaitForSelectorAsync("id=appbar");57 // Click through to the desired result58 await page.ClickAsync("a:has-text(\".NET\")");59 });60 }61}...
Keyboard.cs
Source:Keyboard.cs
...24using System.Threading.Tasks;25using Microsoft.Playwright.Transport.Channels;26namespace Microsoft.Playwright.Core27{28 internal class Keyboard : IKeyboard29 {30 private readonly PageChannel _channel;31 public Keyboard(PageChannel channel)32 {33 _channel = channel;34 }35 public Task DownAsync(string key) => _channel.KeyboardDownAsync(key);36 public Task UpAsync(string key) => _channel.KeyboardUpAsync(key);37 public Task PressAsync(string key, KeyboardPressOptions options = default)38 => _channel.PressAsync(key, options?.Delay);39 public Task TypeAsync(string text, KeyboardTypeOptions options = default)40 => _channel.TypeAsync(text, options?.Delay);41 public Task InsertTextAsync(string text) => _channel.InsertTextAsync(text);42 }43}...
Keyboard
Using AI Code Generation
1using Microsoft.Playwright.Core;2using System;3using System.Threading.Tasks;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();9 var context = await browser.NewContextAsync();10 var page = await context.NewPageAsync();11 await page.ClickAsync("input[title='Search']");12 await page.Keyboard.TypeAsync("Hello World");13 }14}15using Microsoft.Playwright.Core;16using System;17using System.Threading.Tasks;18{19 static async Task Main(string[] args)20 {21 using var playwright = await Playwright.CreateAsync();22 await using var browser = await playwright.Chromium.LaunchAsync();23 var context = await browser.NewContextAsync();24 var page = await context.NewPageAsync();25 await page.ClickAsync("input[title='Search']");26 await page.Mouse.ClickAsync(200, 200);27 }28}29using Microsoft.Playwright.Core;30using System;31using System.Threading.Tasks;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 context = await browser.NewContextAsync();38 var page = await context.NewPageAsync();39 await page.ClickAsync("input[title='Search']");40 await page.ClickAsync(Selectors.Text("Google Search"));41 }42}43using Microsoft.Playwright.Core;44using System;45using System.Threading.Tasks;46{47 static async Task Main(string[] args)48 {49 using var playwright = await Playwright.CreateAsync();50 await using var browser = await playwright.Chromium.LaunchAsync();51 var context = await browser.NewContextAsync();52 var page = await context.NewPageAsync();53 await page.ClickAsync("input[title
Keyboard
Using AI Code Generation
1using Microsoft.Playwright.Core;2using System;3using System.Threading.Tasks;4{5 {6 static async Task Main(string[] args)7 {8 using var playwright = await Playwright.CreateAsync();9 var browser = await playwright.Chromium.LaunchAsync(new LaunchOptions { Headless = false });10 var context = await browser.NewContextAsync();11 var page = await context.NewPageAsync();12 await page.TypeAsync("input[title='Search']", "Hello World", new TypeOptions { Delay = 100 });13 await page.ClickAsync("input[value='Google Search']");14 await Task.Delay(5000);15 await browser.CloseAsync();16 }17 }18}19Here is the code to use Task.WhenAll() method:20using Microsoft.Playwright.Core;21using System;22using System.Threading.Tasks;23{24 {25 static async Task Main(string[] args)26 {27 using var playwright = await Playwright.CreateAsync();28 var browser = await playwright.Chromium.LaunchAsync(new LaunchOptions { Headless = false });29 var context = await browser.NewContextAsync();30 var page = await context.NewPageAsync();31 await page.TypeAsync("input[title='Search']", "Hello World", new TypeOptions { Delay = 100 });32 await page.ClickAsync("input[value='Google Search']");33 await Task.WhenAll(Task.Delay(5000), browser.CloseAsync());34 }35 }36}
Keyboard
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 var browser = await playwright.Chromium.LaunchAsync(new LaunchOptions10 {11 });12 var context = await browser.NewContextAsync();13 var page = await context.NewPageAsync();14 await page.TypeAsync("input[name=q]", "Playwright");15 await page.PressAsync("input[name=q]", "Enter");16 await page.ScreenshotAsync("screenshot.png");17 await browser.CloseAsync();18 }19 }20}21using Microsoft.Playwright;22using System;23using System.Threading.Tasks;24{25 {26 static async Task Main(string[] args)27 {28 using var playwright = await Playwright.CreateAsync();29 var browser = await playwright.Chromium.LaunchAsync(new LaunchOptions30 {31 });32 var context = await browser.NewContextAsync();33 var page = await context.NewPageAsync();34 await page.TypeAsync("input[name=q]", "Playwright");35 await page.Keyboard.PressAsync("Enter");36 await page.ScreenshotAsync("screenshot.png");37 await browser.CloseAsync();38 }39 }40}41using Microsoft.Playwright;42using System;43using System.Threading.Tasks;44{45 {46 static async Task Main(string[] args)47 {48 using var playwright = await Playwright.CreateAsync();49 var browser = await playwright.Chromium.LaunchAsync(new LaunchOptions50 {51 });52 var context = await browser.NewContextAsync();53 var page = await context.NewPageAsync();54 await page.TypeAsync("input[name=q]", "Playwright");55 await page.Keyboard.PressAsync("Enter");
Keyboard
Using AI Code Generation
1using Microsoft.Playwright.Core;2using System;3using System.Threading.Tasks;4{5 {6 static async Task Main(string[] args)7 {8 await using var playwright = await Playwright.CreateAsync();9 await using var browser = await playwright.Chromium.LaunchAsync();10 var page = await browser.NewPageAsync();11 }12 }13}
Keyboard
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using Microsoft.Playwright;4{5 {6 static async Task Main(string[] args)7 {8 await 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.TypeAsync("#search", "Keyboard");14 await page.PressAsync("#search", "Enter");15 await page.ScreenshotAsync("example.png");16 }17 }18}19using System;20using System.Threading.Tasks;21using Microsoft.Playwright;22{23 {24 static async Task Main(string[] args)25 {26 await using var playwright = await Playwright.CreateAsync();27 await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions28 {29 });30 var page = await browser.NewPageAsync();31 await page.ClickAsync("text=Get started");32 await page.ClickAsync("text=API reference");33 await page.ClickAsync("text=Examples");34 await page.ClickAsync("text=FAQ");35 await page.ClickAsync("text=Blog");36 await page.ClickAsync("text=Changelog");37 await page.ClickAsync("text=Playwright on GitHub");38 await page.ClickAsync("text=Playwright on Twitter");39 await page.ClickAsync("text=Playwright on YouTube");40 await page.ClickAsync("text=Playwright on GitHub");41 await page.ClickAsync("text=Playwright on Twitter");42 await page.ClickAsync("text=Playwright on YouTube");43 await page.ClickAsync("text=Playwright on GitHub");44 await page.ClickAsync("text=Playwright on Twitter");45 await page.ClickAsync("text=Playwright on
Keyboard
Using AI Code Generation
1using Microsoft.Playwright.Core;2using System;3{4 {5 static async Task Main(string[] args)6 {7 Console.WriteLine("Hello World!");8 using var playwright = await Playwright.CreateAsync();9 var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions10 {11 });12 var context = await browser.NewContextAsync(new BrowserNewContextOptions13 {14 {15 }16 });17 var page = await context.NewPageAsync();18 await page.TypeAsync("input[title='Search']", "Hello World");19 await page.Keyboard.PressAsync("Enter");20 await Task.Delay(2000);21 await browser.CloseAsync();22 }23 }24}
Keyboard
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 LaunchOptions { Headless = false });10 var page = await browser.NewPageAsync();11 var searchBox = await page.QuerySelectorAsync("input[name='q']");12 await searchBox.TypeAsync("Hello World!");13 await searchBox.PressAsync("Enter");14 Console.WriteLine("Press any key to close the browser");15 Console.ReadKey();16 }17 }18}
Keyboard
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 await page.Keyboard.PressAsync("ArrowDown");
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!!