Best Puppeteer-sharp code snippet using PuppeteerSharp.Page.SetDragInterceptionAsync
Page.cs
Source:Page.cs
...388 /// on the page, which can then be used to simulate drag-and-drop.389 /// </remarks>390 /// <param name="enabled">Interception enabled</param>391 /// <returns>A Task that resolves when the message was confirmed by the browser</returns>392 public Task SetDragInterceptionAsync(bool enabled)393 {394 IsDragInterceptionEnabled = enabled;395 return Client.SendAsync("Input.setInterceptDrags", new InputSetInterceptDragsRequest { Enabled = enabled });396 }397 /// <summary>398 /// Returns metrics399 /// </summary>400 /// <returns>Task which resolves into a list of metrics</returns>401 /// <remarks>402 /// All timestamps are in monotonic time: monotonically increasing time in seconds since an arbitrary point in the past.403 /// </remarks>404 public async Task<Dictionary<string, decimal>> MetricsAsync()405 {406 var response = await Client.SendAsync<PerformanceGetMetricsResponse>("Performance.getMetrics").ConfigureAwait(false);...
InputDragTests.cs
Source:InputDragTests.cs
...26 public async Task ShouldEmitADragInterceptedEventWhenDragged()27 {28 await Page.GoToAsync(TestConstants.ServerUrl + "/input/drag-and-drop.html");29 Assert.False(Page.IsDragInterceptionEnabled);30 await Page.SetDragInterceptionAsync(true);31 Assert.True(Page.IsDragInterceptionEnabled);32 var draggable = await Page.QuerySelectorAsync("#drag");33 var data = await draggable.DragAsync(1, 1);34 Assert.Single(data.Items);35 Assert.True(await Page.EvaluateFunctionAsync<bool>("() => globalThis.didDragStart"));36 }37 [PuppeteerTest("drag-and-drop.spec.ts", "Input.drag", "should emit a dragEnter")]38 [SkipBrowserFact(skipFirefox: true)]39 public async Task ShouldEmitADragEnter()40 {41 await Page.GoToAsync(TestConstants.ServerUrl + "/input/drag-and-drop.html");42 Assert.False(Page.IsDragInterceptionEnabled);43 await Page.SetDragInterceptionAsync(true);44 Assert.True(Page.IsDragInterceptionEnabled);45 var draggable = await Page.QuerySelectorAsync("#drag");46 var data = await draggable.DragAsync(1, 1);47 var dropzone = await Page.QuerySelectorAsync("#drop");48 await dropzone.DragEnterAsync(data);49 Assert.True(await Page.EvaluateFunctionAsync<bool>("() => globalThis.didDragStart"));50 Assert.True(await Page.EvaluateFunctionAsync<bool>("() => globalThis.didDragEnter"));51 }52 [PuppeteerTest("drag-and-drop.spec.ts", "Input.drag", "should emit a dragOver event")]53 [SkipBrowserFact(skipFirefox: true)]54 public async Task ShouldEmitADragOver()55 {56 await Page.GoToAsync(TestConstants.ServerUrl + "/input/drag-and-drop.html");57 Assert.False(Page.IsDragInterceptionEnabled);58 await Page.SetDragInterceptionAsync(true);59 Assert.True(Page.IsDragInterceptionEnabled);60 var draggable = await Page.QuerySelectorAsync("#drag");61 var data = await draggable.DragAsync(1, 1);62 var dropzone = await Page.QuerySelectorAsync("#drop");63 await dropzone.DragEnterAsync(data);64 await dropzone.DragOverAsync(data);65 Assert.True(await Page.EvaluateFunctionAsync<bool>("() => globalThis.didDragStart"));66 Assert.True(await Page.EvaluateFunctionAsync<bool>("() => globalThis.didDragEnter"));67 Assert.True(await Page.EvaluateFunctionAsync<bool>("() => globalThis.didDragOver"));68 }69 [PuppeteerTest("drag-and-drop.spec.ts", "Input.drag", "can be dropped")]70 [SkipBrowserFact(skipFirefox: true)]71 public async Task CanBeDropped()72 {73 await Page.GoToAsync(TestConstants.ServerUrl + "/input/drag-and-drop.html");74 Assert.False(Page.IsDragInterceptionEnabled);75 await Page.SetDragInterceptionAsync(true);76 Assert.True(Page.IsDragInterceptionEnabled);77 var draggable = await Page.QuerySelectorAsync("#drag");78 var data = await draggable.DragAsync(1, 1);79 var dropzone = await Page.QuerySelectorAsync("#drop");80 await dropzone.DragEnterAsync(data);81 await dropzone.DragOverAsync(data);82 await dropzone.DropAsync(data);83 Assert.True(await Page.EvaluateFunctionAsync<bool>("() => globalThis.didDragStart"));84 Assert.True(await Page.EvaluateFunctionAsync<bool>("() => globalThis.didDragEnter"));85 Assert.True(await Page.EvaluateFunctionAsync<bool>("() => globalThis.didDragOver"));86 Assert.True(await Page.EvaluateFunctionAsync<bool>("() => globalThis.didDrop"));87 }88 [PuppeteerTest("drag-and-drop.spec.ts", "Input.drag", "can be dragged and dropped with a single function")]89 [SkipBrowserFact(skipFirefox: true)]90 public async Task CanBeDraggedAndDroppedWithASingleFunction()91 {92 await Page.GoToAsync(TestConstants.ServerUrl + "/input/drag-and-drop.html");93 Assert.False(Page.IsDragInterceptionEnabled);94 await Page.SetDragInterceptionAsync(true);95 Assert.True(Page.IsDragInterceptionEnabled);96 var draggable = await Page.QuerySelectorAsync("#drag");97 var dropzone = await Page.QuerySelectorAsync("#drop");98 await draggable.DragAndDropAsync(dropzone);99 Assert.True(await Page.EvaluateFunctionAsync<bool>("() => globalThis.didDragStart"));100 Assert.True(await Page.EvaluateFunctionAsync<bool>("() => globalThis.didDragEnter"));101 Assert.True(await Page.EvaluateFunctionAsync<bool>("() => globalThis.didDragOver"));102 Assert.True(await Page.EvaluateFunctionAsync<bool>("() => globalThis.didDrop"));103 }104 [PuppeteerTest("drag-and-drop.spec.ts", "Input.drag", "can be disabled")]105 [SkipBrowserFact(skipFirefox: true)]106 public async Task CanBeDisabled()107 {108 await Page.GoToAsync(TestConstants.ServerUrl + "/input/drag-and-drop.html");109 Assert.False(Page.IsDragInterceptionEnabled);110 await Page.SetDragInterceptionAsync(true);111 Assert.True(Page.IsDragInterceptionEnabled);112 var draggable = await Page.QuerySelectorAsync("#drag");113 await draggable.DragAsync(1, 1);114 await Page.SetDragInterceptionAsync(false);115 var exception = await Assert.ThrowsAsync<PuppeteerException>(() => draggable.DragAsync(1, 1));116 Assert.Contains("Drag Interception is not enabled!", exception.Message);117 }118 }119}...
SetDragInterceptionAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {8 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);9 var browser = await Puppeteer.LaunchAsync(new LaunchOptions10 {11 Args = new string[] { "--start-maximized" }12 });13 var page = await browser.NewPageAsync();14 await page.WaitForSelectorAsync(".w3-btn");15 await page.ClickAsync(".w3-btn");16 await page.WaitForSelectorAsync("#iframeResult");17 var iframe = await page.QuerySelectorAsync("#iframeResult");18 var frame = await iframe.ContentFrameAsync();19 await frame.WaitForSelectorAsync("#div1");20 var dragElement = await frame.QuerySelectorAsync("#div1");21 await frame.SetDragInterceptionAsync(true);22 await dragElement.DragAsync();23 var dropElement = await frame.QuerySelectorAsync("#div2");24 await dropElement.DropAsync();25 await page.WaitForTimeoutAsync(5000);26 await browser.CloseAsync();27 }28 }29}
SetDragInterceptionAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static void Main(string[] args)7 {8 MainAsync(args).GetAwaiter().GetResult();9 }10 static async Task MainAsync(string[] args)11 {12 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions13 {14 Args = new string[] { "--window-size=1920,1080" }15 }))16 {17 var page = await browser.NewPageAsync();18 await page.SetViewportAsync(new ViewPortOptions19 {20 });21 await page.SetDragInterceptionAsync(true);22 await page.Mouse.MoveAsync(100, 100);23 await page.Mouse.DownAsync();24 await page.Mouse.MoveAsync(100, 200);25 await page.Mouse.UpAsync();26 await page.SetDragInterceptionAsync(false);27 }28 }
SetDragInterceptionAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {8 await new BrowserFetcher().DownloadAsync();9 var browser = await Puppeteer.LaunchAsync(new LaunchOptions10 {11 });12 var page = await browser.NewPageAsync();13 await page.SetDragInterceptionAsync(true);14 await browser.CloseAsync();15 }16 }17}
SetDragInterceptionAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {8 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);9 var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false, DefaultViewport = null });10 var page = await browser.NewPageAsync();11 await page.SetDragInterceptionAsync(true);12 await page.DragAsync("#drag1", "#div2");13 await page.SetDragInterceptionAsync(false);14 await page.DragAsync("#drag1", "#div2");15 }16 }17}
SetDragInterceptionAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static async Task Main(string[] args)7 {8 {9 Args = new string[] { "--start-maximized" }10 };11 using (var browser = await Puppeteer.LaunchAsync(options))12 using (var page = await browser.NewPageAsync())13 {14 await page.SetDragInterceptionAsync(true);15 var dragSource = await page.QuerySelectorAsync("#drag1");16 await dragSource.DragAsync();17 var dropTarget = await page.QuerySelectorAsync("#div2");18 await dropTarget.DropAsync();19 await page.SetDragInterceptionAsync(false);20 }21 }22 }23}
SetDragInterceptionAsync
Using AI Code Generation
1using System.Threading.Tasks;2using PuppeteerSharp;3using System;4{5 {6 static void Main(string[] args)7 {8 MainAsync().Wait();9 }10 static async Task MainAsync()11 {12 var options = new LaunchOptions { Headless = false };13 using (var browser = await Puppeteer.LaunchAsync(options))14 using (var page = await browser.NewPageAsync())15 {16 await page.SetDragInterceptionAsync(true);17 var dragElement = await page.QuerySelectorAsync("#drag1");18 var dropElement = await page.QuerySelectorAsync("#div2");19 await dragElement.DragAndDropAsync(dropElement);20 await page.SetDragInterceptionAsync(false);21 Console.Read();22 }23 }24 }25}
SetDragInterceptionAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static void Main(string[] args)7 {8 MainAsync(args).Wait();9 }10 static async Task MainAsync(string[] args)11 {12 {13 Args = new string[] { "--disable-drag" }14 };15 using (var browser = await Puppeteer.LaunchAsync(options))16 {17 var page = await browser.NewPageAsync();18 await page.SetDragInterceptionAsync(true);19 await page.DragAndDropAsync("#hplogo", "#gbqfbb");20 await browser.CloseAsync();21 }22 }23 }24}
SetDragInterceptionAsync
Using AI Code Generation
1using PuppeteerSharp;2using System.Threading.Tasks;3using PuppeteerSharp.Input;4using System;5{6 {7 static void Main(string[] args)8 {9 MainAsync().Wait();10 }11 static async Task MainAsync()12 {13 var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false });14 var page = await browser.NewPageAsync();15 await page.SetDragInterceptionAsync(false);16 await page.DragAndDropAsync("#drag1", "#div2");17 await page.WaitForTimeoutAsync(2000);18 await page.SetDragInterceptionAsync(true);19 await page.DragAndDropAsync("#drag1", "#div2");20 await page.WaitForTimeoutAsync(2000);21 await browser.CloseAsync();22 }23 }24}
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!!