Best Puppeteer-sharp code snippet using PuppeteerSharp.Input.Keyboard.DownAsync
KeyboardTests.cs
Source:KeyboardTests.cs
...31 _ = Page.Keyboard.PressAsync("ArrowLeft");32 }33 await Page.Keyboard.TypeAsync("inserted ");34 Assert.Equal("Hello inserted World!", await Page.EvaluateExpressionAsync<string>("document.querySelector('textarea').value"));35 _ = Page.Keyboard.DownAsync("Shift");36 for (var i = 0; i < "inserted ".Length; i++)37 {38 _ = Page.Keyboard.PressAsync("ArrowLeft");39 }40 _ = Page.Keyboard.UpAsync("Shift");41 await Page.Keyboard.PressAsync("Backspace");42 Assert.Equal("Hello World!", await Page.EvaluateExpressionAsync<string>("document.querySelector('textarea').value"));43 }44 [Fact]45 public async Task ShouldSendACharacterWithElementHandlePress()46 {47 await Page.GoToAsync(TestConstants.ServerUrl + "/input/textarea.html");48 var textarea = await Page.QuerySelectorAsync("textarea");49 await textarea.PressAsync("a");50 Assert.Equal("a", await Page.EvaluateExpressionAsync<string>("document.querySelector('textarea').value"));51 await Page.EvaluateExpressionAsync("window.addEventListener('keydown', e => e.preventDefault(), true)");52 await textarea.PressAsync("b");53 Assert.Equal("a", await Page.EvaluateExpressionAsync<string>("document.querySelector('textarea').value"));54 }55 [Fact]56 public async Task ElementHandlePressShouldSupportTextOption()57 {58 await Page.GoToAsync(TestConstants.ServerUrl + "/input/textarea.html");59 var textarea = await Page.QuerySelectorAsync("textarea");60 await textarea.PressAsync("a", new PressOptions { Text = "Ñ" });61 Assert.Equal("Ñ", await Page.EvaluateExpressionAsync<string>("document.querySelector('textarea').value"));62 }63 [Fact]64 public async Task ShouldSendACharacterWithSendCharacter()65 {66 await Page.GoToAsync(TestConstants.ServerUrl + "/input/textarea.html");67 await Page.FocusAsync("textarea");68 await Page.Keyboard.SendCharacterAsync("å¨");69 Assert.Equal("å¨", await Page.EvaluateExpressionAsync<string>("document.querySelector('textarea').value"));70 await Page.EvaluateExpressionAsync("window.addEventListener('keydown', e => e.preventDefault(), true)");71 await Page.Keyboard.SendCharacterAsync("a");72 Assert.Equal("å¨a", await Page.EvaluateExpressionAsync<string>("document.querySelector('textarea').value"));73 }74 [Fact]75 public async Task ShouldReportShiftKey()76 {77 await Page.GoToAsync(TestConstants.ServerUrl + "/input/keyboard.html");78 var keyboard = Page.Keyboard;79 var codeForKey = new Dictionary<string, int> { ["Shift"] = 16, ["Alt"] = 18, ["Control"] = 17 };80 foreach (var modifier in codeForKey)81 {82 await keyboard.DownAsync(modifier.Key);83 Assert.Equal($"Keydown: {modifier.Key} {modifier.Key}Left {modifier.Value} [{modifier.Key}]", await Page.EvaluateExpressionAsync<string>("getResult()"));84 await keyboard.DownAsync("!");85 // Shift+! will generate a keypress86 if (modifier.Key == "Shift")87 {88 Assert.Equal($"Keydown: ! Digit1 49 [{modifier.Key}]\nKeypress: ! Digit1 33 33 [{modifier.Key}]", await Page.EvaluateExpressionAsync<string>("getResult()"));89 }90 else91 {92 Assert.Equal($"Keydown: ! Digit1 49 [{modifier.Key}]", await Page.EvaluateExpressionAsync<string>("getResult()"));93 }94 await keyboard.UpAsync("!");95 Assert.Equal($"Keyup: ! Digit1 49 [{modifier.Key}]", await Page.EvaluateExpressionAsync<string>("getResult()"));96 await keyboard.UpAsync(modifier.Key);97 Assert.Equal($"Keyup: {modifier.Key} {modifier.Key}Left {modifier.Value} []", await Page.EvaluateExpressionAsync<string>("getResult()"));98 }99 }100 [Fact]101 public async Task ShouldReportMultipleModifiers()102 {103 await Page.GoToAsync(TestConstants.ServerUrl + "/input/keyboard.html");104 var keyboard = Page.Keyboard;105 await keyboard.DownAsync("Control");106 Assert.Equal("Keydown: Control ControlLeft 17 [Control]", await Page.EvaluateExpressionAsync<string>("getResult()"));107 await keyboard.DownAsync("Alt");108 Assert.Equal("Keydown: Alt AltLeft 18 [Alt Control]", await Page.EvaluateExpressionAsync<string>("getResult()"));109 await keyboard.DownAsync(";");110 Assert.Equal("Keydown: ; Semicolon 186 [Alt Control]", await Page.EvaluateExpressionAsync<string>("getResult()"));111 await keyboard.UpAsync(";");112 Assert.Equal("Keyup: ; Semicolon 186 [Alt Control]", await Page.EvaluateExpressionAsync<string>("getResult()"));113 await keyboard.UpAsync("Control");114 Assert.Equal("Keyup: Control ControlLeft 17 [Alt]", await Page.EvaluateExpressionAsync<string>("getResult()"));115 await keyboard.UpAsync("Alt");116 Assert.Equal("Keyup: Alt AltLeft 18 []", await Page.EvaluateExpressionAsync<string>("getResult()"));117 }118 [Fact]119 public async Task ShouldSendProperCodesWhileTyping()120 {121 await Page.GoToAsync(TestConstants.ServerUrl + "/input/keyboard.html");122 await Page.Keyboard.TypeAsync("!");123 Assert.Equal(string.Join("\n", new[] {124 "Keydown: ! Digit1 49 []",125 "Keypress: ! Digit1 33 33 []",126 "Keyup: ! Digit1 49 []" }), await Page.EvaluateExpressionAsync<string>("getResult()"));127 await Page.Keyboard.TypeAsync("^");128 Assert.Equal(string.Join("\n", new[] {129 "Keydown: ^ Digit6 54 []",130 "Keypress: ^ Digit6 94 94 []",131 "Keyup: ^ Digit6 54 []" }), await Page.EvaluateExpressionAsync<string>("getResult()"));132 }133 [Fact]134 public async Task ShouldSendProperCodesWhileTypingWithShift()135 {136 await Page.GoToAsync(TestConstants.ServerUrl + "/input/keyboard.html");137 var keyboard = Page.Keyboard;138 await keyboard.DownAsync("Shift");139 await Page.Keyboard.TypeAsync("~");140 Assert.Equal(string.Join("\n", new[] {141 "Keydown: Shift ShiftLeft 16 [Shift]",142 "Keydown: ~ Backquote 192 [Shift]", // 192 is ` keyCode143 "Keypress: ~ Backquote 126 126 [Shift]", // 126 is ~ charCode144 "Keyup: ~ Backquote 192 [Shift]" }), await Page.EvaluateExpressionAsync<string>("getResult()"));145 await keyboard.UpAsync("Shift");146 }147 [Fact]148 public async Task ShouldNotTypeCanceledEvents()149 {150 await Page.GoToAsync(TestConstants.ServerUrl + "/input/textarea.html");151 await Page.FocusAsync("textarea");152 await Page.EvaluateExpressionAsync(@"{153 window.addEventListener('keydown', event => {154 event.stopPropagation();155 event.stopImmediatePropagation();156 if (event.key === 'l')157 event.preventDefault();158 if (event.key === 'o')159 event.preventDefault();160 }, false);161 }");162 await Page.Keyboard.TypeAsync("Hello World!");163 Assert.Equal("He Wrd!", await Page.EvaluateExpressionAsync<string>("textarea.value"));164 }165 [Fact]166 public async Task ShouldSpecifyRepeatProperty()167 {168 await Page.GoToAsync(TestConstants.ServerUrl + "/input/textarea.html");169 await Page.FocusAsync("textarea");170 await Page.EvaluateExpressionAsync("document.querySelector('textarea').addEventListener('keydown', e => window.lastEvent = e, true)");171 await Page.Keyboard.DownAsync("a");172 Assert.False(await Page.EvaluateExpressionAsync<bool>("window.lastEvent.repeat"));173 await Page.Keyboard.PressAsync("a");174 Assert.True(await Page.EvaluateExpressionAsync<bool>("window.lastEvent.repeat"));175 await Page.Keyboard.DownAsync("b");176 Assert.False(await Page.EvaluateExpressionAsync<bool>("window.lastEvent.repeat"));177 await Page.Keyboard.DownAsync("b");178 Assert.True(await Page.EvaluateExpressionAsync<bool>("window.lastEvent.repeat"));179 await Page.Keyboard.UpAsync("a");180 await Page.Keyboard.DownAsync("a");181 Assert.False(await Page.EvaluateExpressionAsync<bool>("window.lastEvent.repeat"));182 }183 [Fact]184 public async Task ShouldTypeAllKindsOfCharacters()185 {186 await Page.GoToAsync(TestConstants.ServerUrl + "/input/textarea.html");187 await Page.FocusAsync("textarea");188 const string text = "This text goes onto two lines.\nThis character is å¨.";189 await Page.Keyboard.TypeAsync(text);190 Assert.Equal(text, await Page.EvaluateExpressionAsync<string>("result"));191 }192 [Fact]193 public async Task ShouldSpecifyLocation()194 {...
Keyboard.cs
Source:Keyboard.cs
...6{7 /// <summary>8 /// Keyboard provides an api for managing a virtual keyboard. The high level api is <see cref="TypeAsync(string, TypeOptions)"/>, which takes raw characters and generates proper keydown, keypress/input, and keyup events on your page.9 /// 10 /// For finer control, you can use <see cref="Keyboard.DownAsync(string, DownOptions)"/>, <see cref="UpAsync(string)"/>, and <see cref="SendCharacterAsync(string)"/> to manually fire events as if they were generated from a real keyboard.11 /// </summary>12 public class Keyboard13 {14 private readonly CDPSession _client;15 private readonly HashSet<string> _pressedKeys = new HashSet<string>();16 internal int Modifiers { get; set; }17 internal Keyboard(CDPSession client)18 {19 _client = client;20 }21 /// <summary>22 /// Dispatches a <c>keydown</c> event23 /// </summary>24 /// <param name="key">Name of key to press, such as <c>ArrowLeft</c>. <see cref="KeyDefinitions"/> for a list of all key names.</param>25 /// <param name="options">down options</param>26 /// <remarks>27 /// If <c>key</c> is a single character and no modifier keys besides <c>Shift</c> are being held down, a <c>keypress</c>/<c>input</c> event will also generated. The <c>text</c> option can be specified to force an input event to be generated.28 /// If <c>key</c> is a modifier key, <c>Shift</c>, <c>Meta</c>, <c>Control</c>, or <c>Alt</c>, subsequent key presses will be sent with that modifier active. To release the modifier key, use <see cref="UpAsync(string)"/>29 /// After the key is pressed once, subsequent calls to <see cref="DownAsync(string, DownOptions)"/> will have <see href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/repeat">repeat</see> set to <c>true</c>. To release the key, use <see cref="UpAsync(string)"/>30 /// </remarks>31 /// <returns>Task</returns>32 public Task DownAsync(string key, DownOptions options = null)33 {34 var description = KeyDescriptionForString(key);35 var autoRepeat = _pressedKeys.Contains(description.Code);36 _pressedKeys.Add(description.Code);37 Modifiers |= ModifierBit(key);38 var text = options?.Text == null ? description.Text : options.Text;39 return _client.SendAsync("Input.dispatchKeyEvent", new Dictionary<string, object>40 {41 { MessageKeys.Type, text != null ? "keyDown" : "rawKeyDown" },42 { MessageKeys.Modifiers, Modifiers },43 { MessageKeys.WindowsVirtualKeyCode, description.KeyCode },44 { MessageKeys.Code, description.Code },45 { MessageKeys.Key, description.Key },46 { MessageKeys.Text, text },47 { MessageKeys.UnmodifiedText, text },48 { MessageKeys.AutoRepeat, autoRepeat },49 { MessageKeys.Location, description.Location },50 { MessageKeys.IsKeypad, description.Location == 3 }51 });52 }53 /// <summary>54 /// Dispatches a <c>keyup</c> event.55 /// </summary>56 /// <param name="key">Name of key to release, such as `ArrowLeft`. See <see cref="KeyDefinitions"/> for a list of all key names.</param>57 /// <returns>Task</returns>58 public Task UpAsync(string key)59 {60 var description = KeyDescriptionForString(key);61 Modifiers &= ~ModifierBit(key);62 _pressedKeys.Remove(description.Code);63 return _client.SendAsync("Input.dispatchKeyEvent", new Dictionary<string, object>64 {65 { MessageKeys.Type, "keyUp" },66 { MessageKeys.Modifiers, Modifiers },67 { MessageKeys.Key, description.Key },68 { MessageKeys.WindowsVirtualKeyCode, description.KeyCode },69 { MessageKeys.Code, description.Code },70 { MessageKeys.Location, description.Location }71 });72 }73 /// <summary>74 /// Dispatches a <c>keypress</c> and <c>input</c> event. This does not send a <c>keydown</c> or <c>keyup</c> event.75 /// </summary>76 /// <param name="charText">Character to send into the page</param>77 /// <returns>Task</returns>78 public Task SendCharacterAsync(string charText)79 => _client.SendAsync("Input.insertText", new Dictionary<string, object> { [MessageKeys.Text] = charText });80 /// <summary>81 /// Sends a <c>keydown</c>, <c>keypress</c>/<c>input</c>, and <c>keyup</c> event for each character in the text.82 /// </summary>83 /// <param name="text">A text to type into a focused element</param>84 /// <param name="options">type options</param>85 /// <remarks>86 /// To press a special key, like <c>Control</c> or <c>ArrowDown</c>, use <see cref="PressAsync(string, PressOptions)"/>87 /// </remarks>88 /// <returns>Task</returns>89 public async Task TypeAsync(string text, TypeOptions options = null)90 {91 var delay = 0;92 if (options?.Delay != null)93 {94 delay = (int)options.Delay;95 }96 var textParts = StringInfo.GetTextElementEnumerator(text);97 while (textParts.MoveNext())98 {99 var letter = textParts.Current;100 if (KeyDefinitions.ContainsKey(letter.ToString()))101 {102 await PressAsync(letter.ToString(), new PressOptions { Delay = delay }).ConfigureAwait(false);103 }104 else105 {106 await SendCharacterAsync(letter.ToString()).ConfigureAwait(false);107 }108 if (delay > 0)109 {110 await Task.Delay(delay).ConfigureAwait(false);111 }112 }113 }114 /// <summary>115 /// Shortcut for <see cref="DownAsync(string, DownOptions)"/> and <see cref="UpAsync(string)"/>116 /// </summary>117 /// <param name="key">Name of key to press, such as <c>ArrowLeft</c>. <see cref="KeyDefinitions"/> for a list of all key names.</param>118 /// <param name="options">press options</param>119 /// <remarks>120 /// If <paramref name="key"/> is a single character and no modifier keys besides <c>Shift</c> are being held down, a <c>keypress</c>/<c>input</c> event will also generated. The <see cref="DownOptions.Text"/> option can be specified to force an input event to be generated.121 /// Modifier keys DO effect <see cref="ElementHandle.PressAsync(string, PressOptions)"/>. Holding down <c>Shift</c> will type the text in upper case.122 /// </remarks>123 /// <returns>Task</returns>124 public async Task PressAsync(string key, PressOptions options = null)125 {126 await DownAsync(key, options).ConfigureAwait(false);127 if (options?.Delay > 0)128 {129 await Task.Delay((int)options.Delay).ConfigureAwait(false);130 }131 await UpAsync(key).ConfigureAwait(false);132 }133 private int ModifierBit(string key)134 {135 if (key == "Alt")136 {137 return 1;138 }139 if (key == "Control")140 {...
DoList.cs
Source:DoList.cs
...28 element = await page.WaitForXPathAsync("/html/body/center[1]/table/tbody/tr/td/table/tbody/tr[10]/td[3]/select");29 await element.ClickAsync();30 //for (int i = 0; i < 9; i ++)31 //{32 // await page.Keyboard.DownAsync("ArrowDown"); 33 //}34 //await page.Keyboard.PressAsync("Enter");35 element = await page.WaitForXPathAsync("/html/body/center[1]/table/tbody/tr/td/table/tbody/tr[15]/td/div/input");36 await element.ClickAsync();37 await page.WaitForTimeoutAsync(4000);38 ////////////////////////////39 ///40 ///ÐÑоÑÐ°Ñ ÑÑÑаниÑа ÐакгÑзки ÐнÑеÑÑейÑа41 //Филиал42 element = await page.WaitForXPathAsync("//*[@id='drdw_CISDIV']");43 await element.ClickAsync();44 for (int i = 0; i < 3; i++)45 {46 await page.Keyboard.DownAsync("ArrowDown");47 }48 await page.Keyboard.PressAsync("Enter");49 //Файл50 element = await page.WaitForXPathAsync("//*[@id='file_FILE']");51 await element.ClickAsync(); 52 await page.WaitForTimeoutAsync(1000);53 KeyBoard($"{filePath.Path}");54 //ÐÑÑоÑник ÐÐУ55 element = await page.WaitForXPathAsync("//*[@id='drdw_SOURCE_CD']");56 //TODO: ÐопиÑаÑÑ Ð²Ñе возможнÑе ваÑиаÑии Ð´Ð»Ñ Ð²ÑбоÑки иÑÑоÑника ÐÐУ иÑÑ
Ð¾Ð´Ñ Ð¸Ð· Ð½Ð°Ð·Ð²Ð°Ð½Ð¸Ñ Ñайла!!!57 var array = await element.QuerySelectorAllAsync("option");58 var ss = await array[0].EvaluateFunctionAsync<string>("e=> e.value");59 await element.SelectAsync($"{filePath.SettingUpload}"); /// Ðнимание на пÑобел!!!!!!!!! option в вÑпадаÑÑем ÑпиÑке Ñ Ð¿Ñобелом, без него не вÑбиÑÐ°ÐµÑ ÑÐ»ÐµÐ¼ÐµÐ½Ñ 60 ///ÐÐÑа61 element = await page.WaitForXPathAsync("//*[@id='dprd_PERIOD']"); /// 62 await element.TypeAsync($"{dateStr}");63 for (int i = 0; i < 7; i++)64 {65 await page.Keyboard.DownAsync("Delete");66 }67 //ÐакÑималÑное колиÑеÑÑво оÑибок68 element = await page.WaitForXPathAsync("//*[@id='nmbr_MAXERROR']"); /// //*[@id="nmbr_MAXERROR"]69 await element.TypeAsync("10000000000");70 for (int i = 0; i < 4; i++)71 {72 await page.Keyboard.DownAsync("Delete");73 }74 element = await page.WaitForXPathAsync("//*[@id='drdw_PUSRCH']");75 await element.ClickAsync();76 await page.Keyboard.DownAsync("ArrowDown");77 await page.Keyboard.PressAsync("Enter");78 //ÐÑполниÑÑ79 element = await page.WaitForXPathAsync("/html/body/center/table/tbody/tr/td/table/tbody/tr[12]/td/div/input");80 //TODO: РазкоменÑиÑоваÑÑ ÑÑÑÐ¾ÐºÑ ÑÑо Ð±Ñ Ð¿ÑогÑамма нажала ÐºÐ½Ð¾Ð¿ÐºÑ "ÐЫÐÐÐÐÐТЬ"81 //await element.ClickAsync();82 ///TODO: ÐолÑÑиÑÑ ÑÐ»ÐµÐ¼ÐµÐ½Ñ Ð¿Ð¾Ñле нажаÑÐ¸Ñ ÐºÐ½Ð¾Ð¿ÐºÐ¸ вÑполниÑÑ83 ///84 //element = await page.WaitForXPathAsync("/html/body/center/table/tbody/tr/td/table/tbody/tr[12]/td/div/input");85 await page.WaitForNavigationAsync(new NavigationOptions { Timeout = 5000000});86 await page.WaitForTimeoutAsync(3000);87 return $"Файл {filePath.Path} загÑÑжен";88 89 }90 catch(Exception ex)...
Program.cs
Source:Program.cs
...50 Thread.Sleep(10000);51 Func<Task> scroll = null;52 scroll = new Func<Task>(async () =>53 {54 await page.Keyboard.DownAsync("ArrowDown");55 });56 for (int i = 0; i < 20; i++)57 {58 Thread.Sleep(300);59 Console.WriteLine("scroll");60 await scroll();61 }62 var jscode = @"() => {63 const selectors = Array.from(document.querySelectorAll(`div.du4w35lb.k4urcfbm.l9j0dhe7.sjgh65i0`)); 64 return selectors.map( t=> {return {content: t.innerHTML}});65 }";66 var results = await page.EvaluateFunctionAsync<Content[]>(jscode);67 List<Data> authorNamesAndText = new List<Data>();68 foreach (var result in results)...
HomeController.cs
Source:HomeController.cs
...69";70 System.Threading.Thread.Sleep(5000);71 for (int i = 0; i < 4; i++)72 {73 await page.Keyboard.DownAsync(key: "Tab");74 System.Threading.Thread.Sleep(500);75 }76 await page.Keyboard.TypeAsync("zawarmehmood.2003@gmail.com", new TypeOptions { Delay = 200 });77 await page.Keyboard.DownAsync(key: "Tab");78 await page.Keyboard.TypeAsync("Zawar123!@#", new TypeOptions { Delay = 200 });79 await page.EvaluateExpressionAsync(ClickButton("Log In", true));80 System.Threading.Thread.Sleep(5000);81 await page.EvaluateExpressionAsync(ClickButton("Save Info"));82 System.Threading.Thread.Sleep(5000);83 await page.EvaluateExpressionAsync(ClickButton("Cancel"));84 System.Threading.Thread.Sleep(5000);85 //Dont add await for this86 page.EvaluateExpressionAsync(87 @"document.querySelector(""div[data-testid=new-post-button]"").click()");88 var fileChooser = await page.WaitForFileChooserAsync();89 await fileChooser.AcceptAsync(new string[] { "C:\\Users\\Zawar\\Desktop\\New folder (4)\\cover6.jpg" });90 System.Threading.Thread.Sleep(5000);91 await page.EvaluateExpressionAsync(ClickButton("Next"));92 System.Threading.Thread.Sleep(5000);93 for (int i = 0; i < 4; i++)94 {95 await page.Keyboard.DownAsync(key: "Tab");96 System.Threading.Thread.Sleep(500);97 }98 await page.Keyboard.TypeAsync("Automated caption", new TypeOptions { Delay = 200 });99 await page.EvaluateExpressionAsync(ClickButton("Share"));100 System.Threading.Thread.Sleep(1600000);101 }102 catch (Exception ex)103 {104 }105 }106 }107 }108}109// string loginBtnScript2 = @"...
PupeteerExtensions.cs
Source:PupeteerExtensions.cs
...123 }124 125 public static async Task PressShiftEnterAsync(this Page page)126 {127 await page.Keyboard.DownAsync(Key.Shift);128 await page.Keyboard.PressAsync(Key.Enter);129 await page.Keyboard.UpAsync(Key.Shift);130 }131 132 public static async Task PressControlPaste(this Page page)133 {134 await page.Keyboard.DownAsync(Key.Control);135 await page.Keyboard.PressAsync("V");136 await page.Keyboard.UpAsync(Key.Control);137 }138 }139}...
Mouse.cs
Source:Mouse.cs
...50 }).ConfigureAwait(false);51 }52 }53 /// <summary>54 /// Shortcut for <see cref="MoveAsync(decimal, decimal, MoveOptions)"/>, <see cref="DownAsync(ClickOptions)"/> and <see cref="UpAsync(ClickOptions)"/>55 /// </summary>56 /// <param name="x"></param>57 /// <param name="y"></param>58 /// <param name="options"></param>59 /// <returns>Task</returns>60 public async Task ClickAsync(decimal x, decimal y, ClickOptions options = null)61 {62 options = options ?? new ClickOptions();63 await MoveAsync(x, y).ConfigureAwait(false);64 await DownAsync(options).ConfigureAwait(false);65 if (options.Delay > 0)66 {67 await Task.Delay(options.Delay).ConfigureAwait(false);68 }69 await UpAsync(options).ConfigureAwait(false);70 }71 /// <summary>72 /// Dispatches a <c>mousedown</c> event.73 /// </summary>74 /// <param name="options"></param>75 /// <returns>Task</returns>76 public Task DownAsync(ClickOptions options = null)77 {78 options = options ?? new ClickOptions();79 _button = options.Button;80 return _client.SendAsync("Input.dispatchMouseEvent", new Dictionary<string, object>()81 {82 { MessageKeys.Type, "mousePressed" },83 { MessageKeys.Button, _button },84 { MessageKeys.X, _x },85 { MessageKeys.Y, _y },86 { MessageKeys.Modifiers, _keyboard.Modifiers },87 { MessageKeys.ClickCount, options.ClickCount }88 });89 }90 /// <summary>...
PageExtensions.cs
Source:PageExtensions.cs
...16 public static async Task OvertypeInputAsync(this Page page, string selector, string text)17 {18 await page.WaitForSelectorAsync(selector);19 await page.FocusAsync(selector);20 await page.Keyboard.DownAsync("Control");21 await page.Keyboard.PressAsync("A");22 await page.Keyboard.UpAsync("Control");23 await page.Keyboard.PressAsync("Backspace");24 await page.Keyboard.TypeAsync(text);25 }26 public static async Task ClickOn(this Page page, string selector)27 {28 await page.WaitForSelectorAsync(selector);29 await page.ClickAsync(selector);30 }31 }32}...
DownAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 static async Task Main(string[] args)6 {7 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);8 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false }))9 {10 using (var page = await browser.NewPageAsync())11 {12 await page.Keyboard.DownAsync("Shift");13 await page.Keyboard.DownAsync("Alt");14 await page.Keyboard.DownAsync("Delete");15 await page.Keyboard.UpAsync("Shift");16 await page.Keyboard.UpAsync("Alt");17 await page.Keyboard.UpAsync("Delete");18 }19 }20 }21}22using System;23using System.Threading.Tasks;24using PuppeteerSharp;25{26 static async Task Main(string[] args)27 {28 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);29 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false }))30 {31 using (var page = await browser.NewPageAsync())32 {33 await page.Keyboard.PressAsync("Shift");34 await page.Keyboard.PressAsync("Alt");35 await page.Keyboard.PressAsync("Delete");36 await page.Keyboard.PressAsync("Shift");37 await page.Keyboard.PressAsync("Alt");38 await page.Keyboard.PressAsync("Delete");39 }40 }41 }42}43using System;44using System.Threading.Tasks;45using PuppeteerSharp;46{47 static async Task Main(string[] args)48 {49 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);50 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false }))51 {52 using (var page = await browser.NewPageAsync())53 {54 await page.Keyboard.SendCharacterAsync("Shift");55 await page.Keyboard.SendCharacterAsync("Alt");56 await page.Keyboard.SendCharacterAsync("Delete");57 await page.Keyboard.SendCharacterAsync("Shift");58 await page.Keyboard.SendCharacterAsync("Alt");
DownAsync
Using AI Code Generation
1var options = new LaunchOptions { Headless = false };2var browser = await Puppeteer.LaunchAsync(options);3var page = await browser.NewPageAsync();4await page.Keyboard.DownAsync("ControlLeft");5await page.Keyboard.DownAsync("KeyA");6await page.Keyboard.UpAsync("ControlLeft");7await page.Keyboard.UpAsync("KeyA");8await page.Keyboard.TypeAsync("Hello World");9await page.ScreenshotAsync("1.png");10var options = new LaunchOptions { Headless = false };11var browser = await Puppeteer.LaunchAsync(options);12var page = await browser.NewPageAsync();13await page.Keyboard.DownAsync("ControlLeft");14await page.Keyboard.DownAsync("KeyA");15await page.Keyboard.UpAsync("ControlLeft");16await page.Keyboard.UpAsync("KeyA");17await page.Keyboard.TypeAsync("Hello World");18await page.ScreenshotAsync("2.png");19var options = new LaunchOptions { Headless = false };20var browser = await Puppeteer.LaunchAsync(options);21var page = await browser.NewPageAsync();22await page.Keyboard.DownAsync("ControlLeft");23await page.Keyboard.DownAsync("KeyA");24await page.Keyboard.UpAsync("ControlLeft");25await page.Keyboard.UpAsync("KeyA");26await page.Keyboard.TypeAsync("Hello World");27await page.ScreenshotAsync("3.png");28var options = new LaunchOptions { Headless = false };29var browser = await Puppeteer.LaunchAsync(options);30var page = await browser.NewPageAsync();31await page.Keyboard.DownAsync("ControlLeft");32await page.Keyboard.DownAsync("KeyA");33await page.Keyboard.UpAsync("ControlLeft");34await page.Keyboard.UpAsync("KeyA");35await page.Keyboard.TypeAsync("Hello World");36await page.ScreenshotAsync("4.png");37var options = new LaunchOptions { Headless = false };
DownAsync
Using AI Code Generation
1var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false });2var page = await browser.NewPageAsync();3await page.TypeAsync("input[name='q']", "Puppeteer", new TypeOptions { Delay = 100 });4await page.Keyboard.DownAsync("Enter");5await page.WaitForNavigationAsync();6public Task DownAsync(string key, object options = null)7using System;8using System.Threading.Tasks;9using PuppeteerSharp;10{11 {12 static async Task Main(string[] args)13 {14 var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false });15 var page = await browser.NewPageAsync();16 await page.TypeAsync("input[name='q']", "Puppeteer", new TypeOptions { Delay = 100 });17 await page.Keyboard.DownAsync("Enter");18 await page.WaitForNavigationAsync();19 }20 }21}22public Task PressAsync(string key, object options = null)23using System;24using System.Threading.Tasks;25using PuppeteerSharp;26{27 {
DownAsync
Using AI Code Generation
1var page = await browser.NewPageAsync();2await page.Keyboard.DownAsync("ArrowDown");3await page.Keyboard.UpAsync("ArrowDown");4await page.ScreenshotAsync("1.png");5var page = await browser.NewPageAsync();6await page.Keyboard.DownAsync("ArrowDown");7await page.Keyboard.UpAsync("ArrowDown");8await page.ScreenshotAsync("2.png");9var page = await browser.NewPageAsync();10await page.Keyboard.DownAsync("ArrowDown");11await page.Keyboard.UpAsync("ArrowDown");12await page.ScreenshotAsync("3.png");13var page = await browser.NewPageAsync();14await page.Keyboard.DownAsync("ArrowDown");15await page.Keyboard.UpAsync("ArrowDown");16await page.ScreenshotAsync("4.png");17var page = await browser.NewPageAsync();18await page.Keyboard.DownAsync("ArrowDown");19await page.Keyboard.UpAsync("ArrowDown");20await page.ScreenshotAsync("5.png");21var page = await browser.NewPageAsync();22await page.Keyboard.DownAsync("ArrowDown");23await page.Keyboard.UpAsync("ArrowDown");24await page.ScreenshotAsync("6.png");25var page = await browser.NewPageAsync();
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!