Best Puppeteer-sharp code snippet using PuppeteerSharp.Frame.SetContentAsync
ClickTests.cs
Source:ClickTests.cs
...21 }22 [Fact]23 public async Task ShouldClickSvg()24 {25 await Page.SetContentAsync($@"26 <svg height=""100"" width=""100"">27 <circle onclick=""javascript:window.__CLICKED=42"" cx=""50"" cy=""50"" r=""40"" stroke=""black"" stroke-width=""3"" fill=""red""/>28 </svg>29 ");30 await Page.ClickAsync("circle");31 Assert.Equal(42, await Page.EvaluateFunctionAsync<int>("() => window.__CLICKED"));32 }33 [Fact]34 public async Task ShouldClickTheButtonIfWindowNodeIsRemoved()35 {36 await Page.GoToAsync(TestConstants.ServerUrl + "/input/button.html");37 await Page.EvaluateExpressionAsync("delete window.Node");38 await Page.ClickAsync("button");39 Assert.Equal("Clicked", await Page.EvaluateExpressionAsync("result"));40 }41 [Fact(Skip = "See https://github.com/GoogleChrome/puppeteer/issues/4281")]42 public async Task ShouldClickOnASpanWithAnInlineElementInside()43 {44 await Page.SetContentAsync($@"45 <style>46 span::before {{47 content: 'q';48 }}49 </style>50 <span onclick='javascript:window.CLICKED=42'></span>51 ");52 await Page.ClickAsync("span");53 Assert.Equal(42, await Page.EvaluateFunctionAsync<int>("() => window.CLICKED"));54 }55 /// <summary>56 /// This test is called ShouldNotThrowUnhandledPromiseRejectionWhenPageCloses in puppeteer.57 /// </summary>58 [Fact]59 public async Task ShouldGracefullyFailWhenPageCloses()60 {61 var newPage = await Browser.NewPageAsync();62 await Assert.ThrowsAsync<TargetClosedException>(() => Task.WhenAll(63 newPage.CloseAsync(),64 newPage.Mouse.ClickAsync(1, 2)65 ));66 }67 [Fact]68 public async Task ShouldClickTheButtonAfterNavigation()69 {70 await Page.GoToAsync(TestConstants.ServerUrl + "/input/button.html");71 await Page.ClickAsync("button");72 await Page.GoToAsync(TestConstants.ServerUrl + "/input/button.html");73 await Page.ClickAsync("button");74 Assert.Equal("Clicked", await Page.EvaluateExpressionAsync<string>("result"));75 }76 [Fact]77 public async Task ShouldClickWithDisabledJavascript()78 {79 await Page.SetJavaScriptEnabledAsync(false);80 await Page.GoToAsync(TestConstants.ServerUrl + "/wrappedlink.html");81 await Task.WhenAll(82 Page.ClickAsync("a"),83 Page.WaitForNavigationAsync()84 );85 Assert.Equal(TestConstants.ServerUrl + "/wrappedlink.html#clicked", Page.Url);86 }87 [Fact]88 public async Task ShouldClickWhenOneOfInlineBoxChildrenIsOutsideOfViewport()89 {90 await Page.SetContentAsync($@"91 <style>92 i {{93 position: absolute;94 top: -1000px;95 }}96 </style>97 <span onclick='javascript:window.CLICKED = 42;'><i>woof</i><b>doggo</b></span>98 ");99 await Page.ClickAsync("span");100 Assert.Equal(42, await Page.EvaluateFunctionAsync<int>("() => window.CLICKED"));101 }102 [Fact]103 public async Task ShouldSelectTheTextByTripleClicking()104 {105 await Page.GoToAsync(TestConstants.ServerUrl + "/input/textarea.html");106 await Page.FocusAsync("textarea");107 const string text = "This is the text that we are going to try to select. Let's see how it goes.";108 await Page.Keyboard.TypeAsync(text);109 await Page.ClickAsync("textarea");110 await Page.ClickAsync("textarea", new ClickOptions { ClickCount = 2 });111 await Page.ClickAsync("textarea", new ClickOptions { ClickCount = 3 });112 Assert.Equal(text, await Page.EvaluateExpressionAsync<string>("window.getSelection().toString()"));113 }114 [Fact]115 public async Task ShouldClickOffscreenButtons()116 {117 await Page.GoToAsync(TestConstants.ServerUrl + "/offscreenbuttons.html");118 var messages = new List<string>();119 Page.Console += (sender, e) => messages.Add(e.Message.Text);120 for (var i = 0; i < 11; ++i)121 {122 // We might've scrolled to click a button - reset to (0, 0).123 await Page.EvaluateFunctionAsync("() => window.scrollTo(0, 0)");124 await Page.ClickAsync($"#btn{i}");125 }126 Assert.Equal(new List<string>127 {128 "button #0 clicked",129 "button #1 clicked",130 "button #2 clicked",131 "button #3 clicked",132 "button #4 clicked",133 "button #5 clicked",134 "button #6 clicked",135 "button #7 clicked",136 "button #8 clicked",137 "button #9 clicked",138 "button #10 clicked"139 }, messages);140 }141 [Fact]142 public async Task ShouldClickWrappedLinks()143 {144 await Page.GoToAsync(TestConstants.ServerUrl + "/wrappedlink.html");145 await Page.ClickAsync("a");146 Assert.True(await Page.EvaluateExpressionAsync<bool>("window.__clicked"));147 }148 [Fact]149 public async Task ShouldClickOnCheckboxInputAndToggle()150 {151 await Page.GoToAsync(TestConstants.ServerUrl + "/input/checkbox.html");152 Assert.Null(await Page.EvaluateExpressionAsync("result.check"));153 await Page.ClickAsync("input#agree");154 Assert.True(await Page.EvaluateExpressionAsync<bool>("result.check"));155 Assert.Equal(new[] {156 "mouseover",157 "mouseenter",158 "mousemove",159 "mousedown",160 "mouseup",161 "click",162 "input",163 "change"164 }, await Page.EvaluateExpressionAsync<string[]>("result.events"));165 await Page.ClickAsync("input#agree");166 Assert.False(await Page.EvaluateExpressionAsync<bool>("result.check"));167 }168 [Fact]169 public async Task ShouldClickOnCheckboxLabelAndToggle()170 {171 await Page.GoToAsync(TestConstants.ServerUrl + "/input/checkbox.html");172 Assert.Null(await Page.EvaluateExpressionAsync("result.check"));173 await Page.ClickAsync("label[for=\"agree\"]");174 Assert.True(await Page.EvaluateExpressionAsync<bool>("result.check"));175 Assert.Equal(new[] {176 "click",177 "input",178 "change"179 }, await Page.EvaluateExpressionAsync<string[]>("result.events"));180 await Page.ClickAsync("label[for=\"agree\"]");181 Assert.False(await Page.EvaluateExpressionAsync<bool>("result.check"));182 }183 [Fact]184 public async Task ShouldFailToClickAMissingButton()185 {186 await Page.GoToAsync(TestConstants.ServerUrl + "/input/button.html");187 var exception = await Assert.ThrowsAsync<SelectorException>(()188 => Page.ClickAsync("button.does-not-exist"));189 Assert.Equal("No node found for selector: button.does-not-exist", exception.Message);190 Assert.Equal("button.does-not-exist", exception.Selector);191 }192 [Fact]193 public async Task ShouldScrollAndClickTheButton()194 {195 await Page.GoToAsync(TestConstants.ServerUrl + "/input/scrollable.html");196 await Page.ClickAsync("#button-5");197 Assert.Equal("clicked", await Page.EvaluateExpressionAsync<string>("document.querySelector(\"#button-5\").textContent"));198 await Page.ClickAsync("#button-80");199 Assert.Equal("clicked", await Page.EvaluateExpressionAsync<string>("document.querySelector(\"#button-80\").textContent"));200 }201 [Fact]202 public async Task ShouldDoubleClickTheButton()203 {204 await Page.GoToAsync(TestConstants.ServerUrl + "/input/button.html");205 await Page.EvaluateExpressionAsync(@"{206 window.double = false;207 const button = document.querySelector('button');208 button.addEventListener('dblclick', event => {209 window.double = true;210 });211 }");212 var button = await Page.QuerySelectorAsync("button");213 await button.ClickAsync(new ClickOptions { ClickCount = 2 });214 Assert.True(await Page.EvaluateExpressionAsync<bool>("double"));215 Assert.Equal("Clicked", await Page.EvaluateExpressionAsync<string>("result"));216 }217 [Fact]218 public async Task ShouldClickAPartiallyObscuredButton()219 {220 await Page.GoToAsync(TestConstants.ServerUrl + "/input/button.html");221 await Page.EvaluateExpressionAsync(@"{222 const button = document.querySelector('button');223 button.textContent = 'Some really long text that will go offscreen';224 button.style.position = 'absolute';225 button.style.left = '368px';226 }");227 await Page.ClickAsync("button");228 Assert.Equal("Clicked", await Page.EvaluateExpressionAsync<string>("result"));229 }230 [Fact]231 public async Task ShouldClickARotatedButton()232 {233 await Page.GoToAsync(TestConstants.ServerUrl + "/input/rotatedButton.html");234 await Page.ClickAsync("button");235 Assert.Equal("Clicked", await Page.EvaluateExpressionAsync<string>("result"));236 }237 [Fact]238 public async Task ShouldFireContextmenuEventOnRightClick()239 {240 await Page.GoToAsync(TestConstants.ServerUrl + "/input/scrollable.html");241 await Page.ClickAsync("#button-8", new ClickOptions { Button = MouseButton.Right });242 Assert.Equal("context menu", await Page.EvaluateExpressionAsync<string>("document.querySelector('#button-8').textContent"));243 }244 // @see https://github.com/GoogleChrome/puppeteer/issues/206245 [Fact]246 public async Task ShouldClickLinksWhichCauseNavigation()247 {248 await Page.SetContentAsync($"<a href=\"{TestConstants.EmptyPage}\">empty.html</a>");249 // This await should not hang.250 await Page.ClickAsync("a");251 }252 [Fact]253 public async Task ShouldClickTheButtonInsideAnIframe()254 {255 await Page.GoToAsync(TestConstants.EmptyPage);256 await Page.SetContentAsync("<div style=\"width:100px;height:100px\">spacer</div>");257 await FrameUtils.AttachFrameAsync(Page, "button-test", TestConstants.ServerUrl + "/input/button.html");258 var frame = Page.FirstChildFrame();259 var button = await frame.QuerySelectorAsync("button");260 await button.ClickAsync();261 Assert.Equal("Clicked", await frame.EvaluateExpressionAsync<string>("window.result"));262 }263 [Fact(Skip = "see https://github.com/GoogleChrome/puppeteer/issues/4110")]264 public async Task ShouldClickTheButtonWithFixedPositionInsideAnIframe()265 {266 await Page.GoToAsync(TestConstants.EmptyPage);267 await Page.SetViewportAsync(new ViewPortOptions268 {269 Width = 500,270 Height = 500271 });272 await Page.SetContentAsync("<div style=\"width:100px;height:2000px\">spacer</div>");273 await FrameUtils.AttachFrameAsync(Page, "button-test", TestConstants.ServerUrl + "/input/button.html");274 var frame = Page.FirstChildFrame();275 await frame.QuerySelectorAsync("button").EvaluateFunctionAsync("button => button.style.setProperty('position', 'fixed')");276 await frame.ClickAsync("button");277 Assert.Equal("Clicked", await frame.EvaluateExpressionAsync<string>("window.result"));278 }279 [Fact]280 public async Task ShouldClickTheButtonWithDeviceScaleFactorSet()281 {282 await Page.SetViewportAsync(new ViewPortOptions { Width = 400, Height = 400, DeviceScaleFactor = 5 });283 Assert.Equal(5, await Page.EvaluateExpressionAsync<int>("window.devicePixelRatio"));284 await Page.SetContentAsync("<div style=\"width:100px;height:100px\">spacer</div>");285 await FrameUtils.AttachFrameAsync(Page, "button-test", TestConstants.ServerUrl + "/input/button.html");286 var frame = Page.FirstChildFrame();287 var button = await frame.QuerySelectorAsync("button");288 await button.ClickAsync();289 Assert.Equal("Clicked", await frame.EvaluateExpressionAsync<string>("window.result"));290 }291 }292}...
FrameWaitForSelectorTests.cs
Source:FrameWaitForSelectorTests.cs
...30 await Page.EvaluateExpressionAsync("delete window.MutationObserver");31 var waitForSelector = Page.WaitForSelectorAsync(".zombo");32 await Task.WhenAll(33 waitForSelector,34 Page.SetContentAsync("<div class='zombo'>anything</div>"));35 Assert.Equal("anything", await Page.EvaluateFunctionAsync<string>("x => x.textContent", await waitForSelector));36 }37 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should resolve promise when node is added")]38 [PuppeteerFact]39 public async Task ShouldResolveTaskWhenNodeIsAdded()40 {41 await Page.GoToAsync(TestConstants.EmptyPage);42 var frame = Page.MainFrame;43 var watchdog = frame.WaitForSelectorAsync("div");44 await frame.EvaluateFunctionAsync(AddElement, "br");45 await frame.EvaluateFunctionAsync(AddElement, "div");46 var eHandle = await watchdog;47 var property = await eHandle.GetPropertyAsync("tagName");48 var tagName = await property.JsonValueAsync<string>();49 Assert.Equal("DIV", tagName);50 }51 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should work when node is added through innerHTML")]52 [PuppeteerFact]53 public async Task ShouldWorkWhenNodeIsAddedThroughInnerHTML()54 {55 await Page.GoToAsync(TestConstants.EmptyPage);56 var watchdog = Page.WaitForSelectorAsync("h3 div");57 await Page.EvaluateFunctionAsync(AddElement, "span");58 await Page.EvaluateExpressionAsync("document.querySelector('span').innerHTML = '<h3><div></div></h3>'");59 await watchdog;60 }61 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "Page.waitForSelector is shortcut for main frame")]62 [PuppeteerFact]63 public async Task PageWaitForSelectorAsyncIsShortcutForMainFrame()64 {65 await Page.GoToAsync(TestConstants.EmptyPage);66 await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage);67 var otherFrame = Page.FirstChildFrame();68 var watchdog = Page.WaitForSelectorAsync("div");69 await otherFrame.EvaluateFunctionAsync(AddElement, "div");70 await Page.EvaluateFunctionAsync(AddElement, "div");71 var eHandle = await watchdog;72 Assert.Equal(Page.MainFrame, eHandle.ExecutionContext.Frame);73 }74 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should run in specified frame")]75 [PuppeteerFact]76 public async Task ShouldRunInSpecifiedFrame()77 {78 await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage);79 await FrameUtils.AttachFrameAsync(Page, "frame2", TestConstants.EmptyPage);80 var frame1 = Page.FirstChildFrame();81 var frame2 = Page.Frames.ElementAt(2);82 var waitForSelectorPromise = frame2.WaitForSelectorAsync("div");83 await frame1.EvaluateFunctionAsync(AddElement, "div");84 await frame2.EvaluateFunctionAsync(AddElement, "div");85 var eHandle = await waitForSelectorPromise;86 Assert.Equal(frame2, eHandle.ExecutionContext.Frame);87 }88 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should throw when frame is detached")]89 [SkipBrowserFact(skipFirefox: true)]90 public async Task ShouldThrowWhenFrameIsDetached()91 {92 await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage);93 var frame = Page.FirstChildFrame();94 var waitTask = frame.WaitForSelectorAsync(".box").ContinueWith(task => task?.Exception?.InnerException);95 await FrameUtils.DetachFrameAsync(Page, "frame1");96 var waitException = await waitTask;97 Assert.NotNull(waitException);98 Assert.Contains("waitForFunction failed: frame got detached.", waitException.Message);99 }100 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should survive cross-process navigation")]101 [PuppeteerFact]102 public async Task ShouldSurviveCrossProcessNavigation()103 {104 var boxFound = false;105 var waitForSelector = Page.WaitForSelectorAsync(".box").ContinueWith(_ => boxFound = true);106 await Page.GoToAsync(TestConstants.EmptyPage);107 Assert.False(boxFound);108 await Page.ReloadAsync();109 Assert.False(boxFound);110 await Page.GoToAsync(TestConstants.CrossProcessHttpPrefix + "/grid.html");111 await waitForSelector;112 Assert.True(boxFound);113 }114 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should wait for visible")]115 [PuppeteerFact]116 public async Task ShouldWaitForVisible()117 {118 var divFound = false;119 var waitForSelector = Page.WaitForSelectorAsync("div", new WaitForSelectorOptions { Visible = true })120 .ContinueWith(_ => divFound = true);121 await Page.SetContentAsync("<div style='display: none; visibility: hidden;'>1</div>");122 Assert.False(divFound);123 await Page.EvaluateExpressionAsync("document.querySelector('div').style.removeProperty('display')");124 Assert.False(divFound);125 await Page.EvaluateExpressionAsync("document.querySelector('div').style.removeProperty('visibility')");126 Assert.True(await waitForSelector);127 Assert.True(divFound);128 }129 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should wait for visible recursively")]130 [PuppeteerFact]131 public async Task ShouldWaitForVisibleRecursively()132 {133 var divVisible = false;134 var waitForSelector = Page.WaitForSelectorAsync("div#inner", new WaitForSelectorOptions { Visible = true })135 .ContinueWith(_ => divVisible = true);136 await Page.SetContentAsync("<div style='display: none; visibility: hidden;'><div id='inner'>hi</div></div>");137 Assert.False(divVisible);138 await Page.EvaluateExpressionAsync("document.querySelector('div').style.removeProperty('display')");139 Assert.False(divVisible);140 await Page.EvaluateExpressionAsync("document.querySelector('div').style.removeProperty('visibility')");141 Assert.True(await waitForSelector);142 Assert.True(divVisible);143 }144 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "hidden should wait for visibility: hidden")]145 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "hidden should wait for display: none")]146 [Theory]147 [InlineData("visibility", "hidden")]148 [InlineData("display", "none")]149 public async Task HiddenShouldWaitForVisibility(string propertyName, string propertyValue)150 {151 var divHidden = false;152 await Page.SetContentAsync("<div style='display: block;'></div>");153 var waitForSelector = Page.WaitForSelectorAsync("div", new WaitForSelectorOptions { Hidden = true })154 .ContinueWith(_ => divHidden = true);155 await Page.WaitForSelectorAsync("div"); // do a round trip156 Assert.False(divHidden);157 await Page.EvaluateExpressionAsync($"document.querySelector('div').style.setProperty('{propertyName}', '{propertyValue}')");158 Assert.True(await waitForSelector);159 Assert.True(divHidden);160 }161 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "hidden should wait for removal")]162 [PuppeteerFact]163 public async Task HiddenShouldWaitForRemoval()164 {165 await Page.SetContentAsync("<div></div>");166 var divRemoved = false;167 var waitForSelector = Page.WaitForSelectorAsync("div", new WaitForSelectorOptions { Hidden = true })168 .ContinueWith(_ => divRemoved = true);169 await Page.WaitForSelectorAsync("div"); // do a round trip170 Assert.False(divRemoved);171 await Page.EvaluateExpressionAsync("document.querySelector('div').remove()");172 Assert.True(await waitForSelector);173 Assert.True(divRemoved);174 }175 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should return null if waiting to hide non-existing element")]176 [PuppeteerFact]177 public async Task ShouldReturnNullIfWaitingToHideNonExistingElement()178 {179 var handle = await Page.WaitForSelectorAsync("non-existing", new WaitForSelectorOptions { Hidden = true });180 Assert.Null(handle);181 }182 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should respect timeout")]183 [PuppeteerFact]184 public async Task ShouldRespectTimeout()185 {186 var exception = await Assert.ThrowsAsync<WaitTaskTimeoutException>(async ()187 => await Page.WaitForSelectorAsync("div", new WaitForSelectorOptions { Timeout = 10 }));188 Assert.Contains("waiting for selector 'div' failed: timeout", exception.Message);189 }190 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should have an error message specifically for awaiting an element to be hidden")]191 [PuppeteerFact]192 public async Task ShouldHaveAnErrorMessageSpecificallyForAwaitingAnElementToBeHidden()193 {194 await Page.SetContentAsync("<div></div>");195 var exception = await Assert.ThrowsAsync<WaitTaskTimeoutException>(async ()196 => await Page.WaitForSelectorAsync("div", new WaitForSelectorOptions { Hidden = true, Timeout = 10 }));197 Assert.Contains("waiting for selector 'div' to be hidden failed: timeout", exception.Message);198 }199 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should respond to node attribute mutation")]200 [PuppeteerFact]201 public async Task ShouldRespondToNodeAttributeMutation()202 {203 var divFound = false;204 var waitForSelector = Page.WaitForSelectorAsync(".zombo").ContinueWith(_ => divFound = true);205 await Page.SetContentAsync("<div class='notZombo'></div>");206 Assert.False(divFound);207 await Page.EvaluateExpressionAsync("document.querySelector('div').className = 'zombo'");208 Assert.True(await waitForSelector);209 }210 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should return the element handle")]211 [PuppeteerFact]212 public async Task ShouldReturnTheElementHandle()213 {214 var waitForSelector = Page.WaitForSelectorAsync(".zombo");215 await Page.SetContentAsync("<div class='zombo'>anything</div>");216 Assert.Equal("anything", await Page.EvaluateFunctionAsync<string>("x => x.textContent", await waitForSelector));217 }218 [PuppeteerTest("waittask.spec.ts", "Frame.waitForSelector", "should have correct stack trace for timeout")]219 [PuppeteerFact]220 public async Task ShouldHaveCorrectStackTraceForTimeout()221 {222 var exception = await Assert.ThrowsAsync<WaitTaskTimeoutException>(async ()223 => await Page.WaitForSelectorAsync(".zombo", new WaitForSelectorOptions { Timeout = 10 }));224 Assert.Contains("WaitForSelectorTests", exception.StackTrace);225 }226 }227}...
WaitForSelectorTests.cs
Source:WaitForSelectorTests.cs
...118 {119 var divFound = false;120 var waitForSelector = Page.WaitForSelectorAsync("div", new WaitForSelectorOptions { Visible = true })121 .ContinueWith(_ => divFound = true);122 await Page.SetContentAsync("<div style='display: none; visibility: hidden;'>1</div>");123 Assert.False(divFound);124 await Page.EvaluateExpressionAsync("document.querySelector('div').style.removeProperty('display')");125 Assert.False(divFound);126 await Page.EvaluateExpressionAsync("document.querySelector('div').style.removeProperty('visibility')");127 Assert.True(await waitForSelector);128 Assert.True(divFound);129 }130 [Fact]131 public async Task ShouldWaitForVisibleRecursively()132 {133 var divVisible = false;134 var waitForSelector = Page.WaitForSelectorAsync("div#inner", new WaitForSelectorOptions { Visible = true })135 .ContinueWith(_ => divVisible = true);136 await Page.SetContentAsync("<div style='display: none; visibility: hidden;'><div id='inner'>hi</div></div>");137 Assert.False(divVisible);138 await Page.EvaluateExpressionAsync("document.querySelector('div').style.removeProperty('display')");139 Assert.False(divVisible);140 await Page.EvaluateExpressionAsync("document.querySelector('div').style.removeProperty('visibility')");141 Assert.True(await waitForSelector);142 Assert.True(divVisible);143 }144 [Theory]145 [InlineData("visibility", "hidden")]146 [InlineData("display", "none")]147 public async Task HiddenShouldWaitForVisibility(string propertyName, string propertyValue)148 {149 var divHidden = false;150 await Page.SetContentAsync("<div style='display: block;'></div>");151 var waitForSelector = Page.WaitForSelectorAsync("div", new WaitForSelectorOptions { Hidden = true })152 .ContinueWith(_ => divHidden = true);153 await Page.WaitForSelectorAsync("div"); // do a round trip154 Assert.False(divHidden);155 await Page.EvaluateExpressionAsync($"document.querySelector('div').style.setProperty('{propertyName}', '{propertyValue}')");156 Assert.True(await waitForSelector);157 Assert.True(divHidden);158 }159 [Fact]160 public async Task HiddenShouldWaitForRemoval()161 {162 await Page.SetContentAsync("<div></div>");163 var divRemoved = false;164 var waitForSelector = Page.WaitForSelectorAsync("div", new WaitForSelectorOptions { Hidden = true })165 .ContinueWith(_ => divRemoved = true);166 await Page.WaitForSelectorAsync("div"); // do a round trip167 Assert.False(divRemoved);168 await Page.EvaluateExpressionAsync("document.querySelector('div').remove()");169 Assert.True(await waitForSelector);170 Assert.True(divRemoved);171 }172 [Fact]173 public async Task ShouldRespectTimeout()174 {175 var exception = await Assert.ThrowsAnyAsync<PuppeteerException>(async ()176 => await Page.WaitForSelectorAsync("div", new WaitForSelectorOptions { Timeout = 10 }));177 Assert.NotNull(exception);178 Assert.Contains("waiting failed: timeout", exception.Message);179 }180 [Fact]181 public async Task ShouldRespondToNodeAttributeMutation()182 {183 var divFound = false;184 var waitForSelector = Page.WaitForSelectorAsync(".zombo").ContinueWith(_ => divFound = true);185 await Page.SetContentAsync("<div class='notZombo'></div>");186 Assert.False(divFound);187 await Page.EvaluateExpressionAsync("document.querySelector('div').className = 'zombo'");188 Assert.True(await waitForSelector);189 }190 [Fact]191 public async Task ShouldReturnTheElementHandle()192 {193 var waitForSelector = Page.WaitForSelectorAsync(".zombo");194 await Page.SetContentAsync("<div class='zombo'>anything</div>");195 Assert.Equal("anything", await Page.EvaluateFunctionAsync<string>("x => x.textContent", await waitForSelector));196 }197 }198}...
PageWaitForNavigationTests.cs
Source:PageWaitForNavigationTests.cs
...62 [SkipBrowserFact(skipFirefox: true)]63 public async Task ShouldWorkWithClickingOnAnchorLinks()64 {65 await Page.GoToAsync(TestConstants.EmptyPage);66 await Page.SetContentAsync("<a href='#foobar'>foobar</a>");67 var navigationTask = Page.WaitForNavigationAsync();68 await Task.WhenAll(69 navigationTask,70 Page.ClickAsync("a")71 );72 Assert.Null(await navigationTask);73 Assert.Equal(TestConstants.EmptyPage + "#foobar", Page.Url);74 }75 [PuppeteerTest("navigation.spec.ts", "Page.waitForNavigation", "should work with history.pushState()")]76 [SkipBrowserFact(skipFirefox: true)]77 public async Task ShouldWorkWithHistoryPushState()78 {79 await Page.GoToAsync(TestConstants.EmptyPage);80 await Page.SetContentAsync(@"81 <a onclick='javascript:pushState()'>SPA</a>82 <script>83 function pushState() { history.pushState({}, '', 'wow.html') }84 </script>85 ");86 var navigationTask = Page.WaitForNavigationAsync();87 await Task.WhenAll(88 navigationTask,89 Page.ClickAsync("a")90 );91 Assert.Null(await navigationTask);92 Assert.Equal(TestConstants.ServerUrl + "/wow.html", Page.Url);93 }94 [PuppeteerTest("navigation.spec.ts", "Page.waitForNavigation", "should work with history.replaceState()")]95 [SkipBrowserFact(skipFirefox: true)]96 public async Task ShouldWorkWithHistoryReplaceState()97 {98 await Page.GoToAsync(TestConstants.EmptyPage);99 await Page.SetContentAsync(@"100 <a onclick='javascript:pushState()'>SPA</a>101 <script>102 function pushState() { history.pushState({}, '', 'replaced.html') }103 </script>104 ");105 var navigationTask = Page.WaitForNavigationAsync();106 await Task.WhenAll(107 navigationTask,108 Page.ClickAsync("a")109 );110 Assert.Null(await navigationTask);111 Assert.Equal(TestConstants.ServerUrl + "/replaced.html", Page.Url);112 }113 [PuppeteerTest("navigation.spec.ts", "Page.waitForNavigation", "should work with DOM history.back()/history.forward()")]114 [SkipBrowserFact(skipFirefox: true)]115 public async Task ShouldWorkWithDOMHistoryBackAndHistoryForward()116 {117 await Page.GoToAsync(TestConstants.EmptyPage);118 await Page.SetContentAsync(@"119 <a id=back onclick='javascript:goBack()'>back</a>120 <a id=forward onclick='javascript:goForward()'>forward</a>121 <script>122 function goBack() { history.back(); }123 function goForward() { history.forward(); }124 history.pushState({}, '', '/first.html');125 history.pushState({}, '', '/second.html');126 </script>127 ");128 Assert.Equal(TestConstants.ServerUrl + "/second.html", Page.Url);129 var navigationTask = Page.WaitForNavigationAsync();130 await Task.WhenAll(131 navigationTask,132 Page.ClickAsync("a#back")...
WaitForNavigationTests.cs
Source:WaitForNavigationTests.cs
...57 [Fact]58 public async Task ShouldWorkWithClickingOnAnchorLinks()59 {60 await Page.GoToAsync(TestConstants.EmptyPage);61 await Page.SetContentAsync("<a href='#foobar'>foobar</a>");62 var navigationTask = Page.WaitForNavigationAsync();63 await Task.WhenAll(64 navigationTask,65 Page.ClickAsync("a")66 );67 Assert.Null(await navigationTask);68 Assert.Equal(TestConstants.EmptyPage + "#foobar", Page.Url);69 }70 [Fact]71 public async Task ShouldWorkWithHistoryPushState()72 {73 await Page.GoToAsync(TestConstants.EmptyPage);74 await Page.SetContentAsync(@"75 <a onclick='javascript:pushState()'>SPA</a>76 <script>77 function pushState() { history.pushState({}, '', 'wow.html') }78 </script>79 ");80 var navigationTask = Page.WaitForNavigationAsync();81 await Task.WhenAll(82 navigationTask,83 Page.ClickAsync("a")84 );85 Assert.Null(await navigationTask);86 Assert.Equal(TestConstants.ServerUrl + "/wow.html", Page.Url);87 }88 [Fact]89 public async Task ShouldWorkWithHistoryReplaceState()90 {91 await Page.GoToAsync(TestConstants.EmptyPage);92 await Page.SetContentAsync(@"93 <a onclick='javascript:pushState()'>SPA</a>94 <script>95 function pushState() { history.pushState({}, '', 'replaced.html') }96 </script>97 ");98 var navigationTask = Page.WaitForNavigationAsync();99 await Task.WhenAll(100 navigationTask,101 Page.ClickAsync("a")102 );103 Assert.Null(await navigationTask);104 Assert.Equal(TestConstants.ServerUrl + "/replaced.html", Page.Url);105 }106 [Fact]107 public async Task ShouldWorkWithDOMHistoryBackAndHistoryForward()108 {109 await Page.GoToAsync(TestConstants.EmptyPage);110 await Page.SetContentAsync(@"111 <a id=back onclick='javascript:goBack()'>back</a>112 <a id=forward onclick='javascript:goForward()'>forward</a>113 <script>114 function goBack() { history.back(); }115 function goForward() { history.forward(); }116 history.pushState({}, '', '/first.html');117 history.pushState({}, '', '/second.html');118 </script>119 ");120 Assert.Equal(TestConstants.ServerUrl + "/second.html", Page.Url);121 var navigationTask = Page.WaitForNavigationAsync();122 await Task.WhenAll(123 navigationTask,124 Page.ClickAsync("a#back")...
FrameWaitForXPathTests.cs
Source:FrameWaitForXPathTests.cs
...18 [PuppeteerTest("waittask.spec.ts", "Frame.waitForXPath", "should support some fancy xpath")]19 [PuppeteerFact]20 public async Task ShouldSupportSomeFancyXpath()21 {22 await Page.SetContentAsync("<p>red herring</p><p>hello world </p>");23 var waitForXPath = Page.WaitForXPathAsync("//p[normalize-space(.)=\"hello world\"]");24 Assert.Equal("hello world ", await Page.EvaluateFunctionAsync<string>("x => x.textContent", await waitForXPath));25 }26 [PuppeteerTest("waittask.spec.ts", "Frame.waitForXPath", "should run in specified frame")]27 [PuppeteerFact]28 public async Task ShouldRunInSpecifiedFrame()29 {30 await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage);31 await FrameUtils.AttachFrameAsync(Page, "frame2", TestConstants.EmptyPage);32 var frame1 = Page.Frames.First(f => f.Name == "frame1");33 var frame2 = Page.Frames.First(f => f.Name == "frame2");34 var waitForXPathPromise = frame2.WaitForXPathAsync("//div");35 await frame1.EvaluateFunctionAsync(addElement, "div");36 await frame2.EvaluateFunctionAsync(addElement, "div");37 var eHandle = await waitForXPathPromise;38 Assert.Equal(frame2, eHandle.ExecutionContext.Frame);39 }40 [PuppeteerTest("waittask.spec.ts", "Frame.waitForXPath", "should throw when frame is detached")]41 [SkipBrowserFact(skipFirefox: true)]42 public async Task ShouldThrowWhenFrameIsDetached()43 {44 await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage);45 var frame = Page.FirstChildFrame();46 var waitPromise = frame.WaitForXPathAsync("//*[@class=\"box\"]");47 await FrameUtils.DetachFrameAsync(Page, "frame1");48 var exception = await Assert.ThrowsAnyAsync<Exception>(() => waitPromise);49 Assert.Contains("waitForFunction failed: frame got detached.", exception.Message);50 }51 [PuppeteerTest("waittask.spec.ts", "Frame.waitForXPath", "hidden should wait for display: none")]52 [PuppeteerFact]53 public async Task HiddenShouldWaitForDisplayNone()54 {55 var divHidden = false;56 await Page.SetContentAsync("<div style='display: block;'></div>");57 var waitForXPath = Page.WaitForXPathAsync("//div", new WaitForSelectorOptions { Hidden = true })58 .ContinueWith(_ => divHidden = true);59 await Page.WaitForXPathAsync("//div"); // do a round trip60 Assert.False(divHidden);61 await Page.EvaluateExpressionAsync("document.querySelector('div').style.setProperty('display', 'none')");62 Assert.True(await waitForXPath.WithTimeout());63 Assert.True(divHidden);64 }65 [PuppeteerTest("waittask.spec.ts", "Frame.waitForXPath", "should return the element handle")]66 [PuppeteerFact]67 public async Task ShouldReturnTheElementHandle()68 {69 var waitForXPath = Page.WaitForXPathAsync("//*[@class=\"zombo\"]");70 await Page.SetContentAsync("<div class='zombo'>anything</div>");71 Assert.Equal("anything", await Page.EvaluateFunctionAsync<string>("x => x.textContent", await waitForXPath));72 }73 [PuppeteerTest("waittask.spec.ts", "Frame.waitForXPath", "should allow you to select a text node")]74 [PuppeteerFact]75 public async Task ShouldAllowYouToSelectATextNode()76 {77 await Page.SetContentAsync("<div>some text</div>");78 var text = await Page.WaitForXPathAsync("//div/text()");79 Assert.Equal(3 /* Node.TEXT_NODE */, await (await text.GetPropertyAsync("nodeType")).JsonValueAsync<int>());80 }81 [PuppeteerTest("waittask.spec.ts", "Frame.waitForXPath", "should allow you to select an element with single slash")]82 [PuppeteerFact]83 public async Task ShouldAllowYouToSelectAnElementWithSingleSlash()84 {85 await Page.SetContentAsync("<div>some text</div>");86 var waitForXPath = Page.WaitForXPathAsync("/html/body/div");87 Assert.Equal("some text", await Page.EvaluateFunctionAsync<string>("x => x.textContent", await waitForXPath));88 }89 [PuppeteerTest("waittask.spec.ts", "Frame.waitForXPath", "should respect timeout")]90 [PuppeteerFact]91 public async Task ShouldRespectTimeout()92 {93 var exception = await Assert.ThrowsAsync<WaitTaskTimeoutException>(()94 => Page.WaitForXPathAsync("//div", new WaitForSelectorOptions { Timeout = 10 }));95 Assert.Contains("waiting for XPath '//div' failed: timeout", exception.Message);96 }97 }98}...
WaitForXPathTests.cs
Source:WaitForXPathTests.cs
...15 }16 [Fact]17 public async Task ShouldSupportSomeFancyXpath()18 {19 await Page.SetContentAsync("<p>red herring</p><p>hello world </p>");20 var waitForXPath = Page.WaitForXPathAsync("//p[normalize-space(.)=\"hello world\"]");21 Assert.Equal("hello world ", await Page.EvaluateFunctionAsync<string>("x => x.textContent", await waitForXPath));22 }23 [Fact]24 public async Task ShouldRunInSpecifiedFrame()25 {26 await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage);27 await FrameUtils.AttachFrameAsync(Page, "frame2", TestConstants.EmptyPage);28 var frame1 = Page.Frames.First(f => f.Name == "frame1");29 var frame2 = Page.Frames.First(f => f.Name == "frame2");30 var waitForXPathPromise = frame2.WaitForXPathAsync("//div");31 await frame1.EvaluateFunctionAsync(addElement, "div");32 await frame2.EvaluateFunctionAsync(addElement, "div");33 var eHandle = await waitForXPathPromise;34 Assert.Equal(frame2, eHandle.ExecutionContext.Frame);35 }36 [Fact]37 public async Task ShouldThrowWhenFrameIsDetached()38 {39 await FrameUtils.AttachFrameAsync(Page, "frame1", TestConstants.EmptyPage);40 var frame = Page.FirstChildFrame();41 var waitPromise = frame.WaitForXPathAsync("//*[@class=\"box\"]");42 await FrameUtils.DetachFrameAsync(Page, "frame1");43 var exception = await Assert.ThrowsAnyAsync<Exception>(() => waitPromise);44 Assert.Contains("waitForFunction failed: frame got detached.", exception.Message);45 }46 [Fact]47 public async Task HiddenShouldWaitForDisplayNone()48 {49 var divHidden = false;50 await Page.SetContentAsync("<div style='display: block;'></div>");51 var waitForXPath = Page.WaitForXPathAsync("//div", new WaitForSelectorOptions { Hidden = true })52 .ContinueWith(_ => divHidden = true);53 await Page.WaitForXPathAsync("//div"); // do a round trip54 Assert.False(divHidden);55 await Page.EvaluateExpressionAsync("document.querySelector('div').style.setProperty('display', 'none')");56 Assert.True(await waitForXPath.WithTimeout());57 Assert.True(divHidden);58 }59 [Fact]60 public async Task ShouldReturnTheElementHandle()61 {62 var waitForXPath = Page.WaitForXPathAsync("//*[@class=\"zombo\"]");63 await Page.SetContentAsync("<div class='zombo'>anything</div>");64 Assert.Equal("anything", await Page.EvaluateFunctionAsync<string>("x => x.textContent", await waitForXPath));65 }66 [Fact]67 public async Task ShouldAllowYouToSelectATextNode()68 {69 await Page.SetContentAsync("<div>some text</div>");70 var text = await Page.WaitForXPathAsync("//div/text()");71 Assert.Equal(3 /* Node.TEXT_NODE */, await (await text.GetPropertyAsync("nodeType")).JsonValueAsync<int>());72 }73 [Fact]74 public async Task ShouldAllowYouToSelectAnElementWithSingleSlash()75 {76 await Page.SetContentAsync("<div>some text</div>");77 var waitForXPath = Page.WaitForXPathAsync("/html/body/div");78 Assert.Equal("some text", await Page.EvaluateFunctionAsync<string>("x => x.textContent", await waitForXPath));79 }80 [Fact]81 public async Task ShouldRespectTimeout()82 {83 var exception = await Assert.ThrowsAsync<WaitTaskTimeoutException>(()84 => Page.WaitForXPathAsync("//div", new WaitForSelectorOptions { Timeout = 10 }));85 Assert.Contains("waiting for XPath '//div' failed: timeout", exception.Message);86 }87 }88}...
BoundingBoxTests.cs
Source:BoundingBoxTests.cs
...52 [PuppeteerTest("elementhandle.spec.ts", "ElementHandle.boundingBox", "should return null for invisible elements")]53 [SkipBrowserFact(skipFirefox: true)]54 public async Task ShouldReturnNullForInvisibleElements()55 {56 await Page.SetContentAsync("<div style='display:none'>hi</div>");57 var elementHandle = await Page.QuerySelectorAsync("div");58 Assert.Null(await elementHandle.BoundingBoxAsync());59 }60 [PuppeteerTest("elementhandle.spec.ts", "ElementHandle.boundingBox", "should force a layout")]61 [SkipBrowserFact(skipFirefox: true)]62 public async Task ShouldForceALayout()63 {64 await Page.SetViewportAsync(new ViewPortOptions { Width = 500, Height = 500 });65 await Page.SetContentAsync("<div style='width: 100px; height: 100px'>hello</div>");66 var elementHandle = await Page.QuerySelectorAsync("div");67 await Page.EvaluateFunctionAsync("element => element.style.height = '200px'", elementHandle);68 var box = await elementHandle.BoundingBoxAsync();69 Assert.Equal(new BoundingBox(8, 8, 100, 200), box);70 }71 [PuppeteerTest("elementhandle.spec.ts", "ElementHandle.boundingBox", "should work with SVG nodes")]72 [SkipBrowserFact(skipFirefox: true)]73 public async Task ShouldWworkWithSVGNodes()74 {75 await Page.SetContentAsync(@"76 <svg xmlns=""http://www.w3.org/2000/svg"" width=""500"" height=""500"">77 <rect id=""theRect"" x=""30"" y=""50"" width=""200"" height=""300""></rect>78 </svg>79 ");80 var element = await Page.QuerySelectorAsync("#therect");81 var pptrBoundingBox = await element.BoundingBoxAsync();82 var webBoundingBox = await Page.EvaluateFunctionAsync<BoundingBox>(@"e =>83 {84 const rect = e.getBoundingClientRect();85 return { x: rect.x, y: rect.y, width: rect.width, height: rect.height};86 }", element);87 Assert.Equal(webBoundingBox, pptrBoundingBox);88 }89 }...
SetContentAsync
Using AI Code Generation
1var page = await browser.NewPageAsync();2await page.SetContentAsync("<!DOCTYPE html><html><head><title>Page Title</title></head><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>");3var title = await page.TitleAsync();4Console.WriteLine(title);5var page = await browser.NewPageAsync();6await page.SetContentAsync("<!DOCTYPE html><html><head><title>Page Title</title></head><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>");7var title = await page.TitleAsync();8Console.WriteLine(title);9var page = await browser.NewPageAsync();10await page.SetContentAsync("<!DOCTYPE html><html><head><title>Page Title</title></head><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>");11var title = await page.TitleAsync();12Console.WriteLine(title);13var page = await browser.NewPageAsync();14await page.SetContentAsync("<!DOCTYPE html><html><head><title>Page Title</title></head><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>");15var title = await page.TitleAsync();16Console.WriteLine(title);17var page = await browser.NewPageAsync();18await page.SetContentAsync("<!DOCTYPE html><html><head><title>Page Title</title></head><body><h1>My First Heading</h1><p>My first paragraph.</p></body></html>");19var title = await page.TitleAsync();20Console.WriteLine(title);
SetContentAsync
Using AI Code Generation
1var frame = await page.GetMainFrameAsync();2var content = await frame.GetContentAsync();3await frame.SetContentAsync(content);4var content = await page.GetContentAsync();5await page.SetContentAsync(content);6var frame = await page.GetMainFrameAsync();7await frame.SetContentAsync("<html><body>hello</body></html>");8await page.SetContentAsync("<html><body>hello</body></html>");9var frame = await page.GetMainFrameAsync();10await frame.SetContentAsync("<html><body>hello</body></html>", new NavigationOptions { WaitUntil = new[] { WaitUntilNavigation.Networkidle0 } });11await page.SetContentAsync("<html><body>hello</body></html>", new NavigationOptions { WaitUntil = new[] { WaitUntilNavigation.Networkidle0 } });12var frame = await page.GetMainFrameAsync();13await frame.SetContentAsync("<html><body>hello</body></html>", new NavigationOptions { WaitUntil = new[] { WaitUntilNavigation.Networkidle0 } });14await page.SetContentAsync("<html><body>hello</body></html>", new NavigationOptions { WaitUntil = new[] { WaitUntilNavigation.Networkidle0 } });15var frame = await page.GetMainFrameAsync();16await frame.SetContentAsync("<html><body>hello</body></html>", new NavigationOptions { WaitUntil = new[] { WaitUntilNavigation.Networkidle0 } });17await page.SetContentAsync("<html><body>hello</body></html>", new NavigationOptions { Wait
SetContentAsync
Using AI Code Generation
1var frame = Page.Frames[1];2await frame.SetContentAsync("<html><body><h1>Hello world</h1></body></html>");3await Page.SetContentAsync("<html><body><h1>Hello world</h1></body></html>");4var frame = Page.Frames[1];5await frame.SetContentAsync("<html><body><h1>Hello world</h1></body></html>");6await Page.SetContentAsync("<html><body><h1>Hello world</h1></body></html>");7var frame = Page.Frames[1];8await frame.SetContentAsync("<html><body><h1>Hello world</h1></body></html>");9await Page.SetContentAsync("<html><body><h1>Hello world</h1></body></html>");10var frame = Page.Frames[1];11await frame.SetContentAsync("<html><body><h1>Hello world</h1></body></html>");12await Page.SetContentAsync("<html><body><h1>Hello world</h1></body></html>");13var frame = Page.Frames[1];14await frame.SetContentAsync("<html><body><h1>Hello world</h1></body></html>");15await Page.SetContentAsync("<html><body><h1>Hello world</h1></body></html>");16var frame = Page.Frames[1];
SetContentAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 public static async Task Main(string[] args)7 {8 Browser browser = await Puppeteer.LaunchAsync(new LaunchOptions9 {10 Args = new string[] { "--no-sandbox" }11 });12 Page page = await browser.NewPageAsync();13 await page.SetContentAsync("<html><body><h1>Hello World</h1></body></html>");14 await page.ScreenshotAsync("1.png");15 }16 }17}18using System;19using System.Threading.Tasks;20using PuppeteerSharp;21{22 {23 public static async Task Main(string[] args)24 {25 Browser browser = await Puppeteer.LaunchAsync(new LaunchOptions26 {27 Args = new string[] { "--no-sandbox" }28 });29 Page page = await browser.NewPageAsync();30 await page.SetContentAsync("<html><body><h1>Hello World</h1></body></html>");31 await page.ScreenshotAsync("2.png");32 }33 }34}35using System;36using System.Threading.Tasks;37using PuppeteerSharp;38{39 {40 public static async Task Main(string[] args)41 {42 Browser browser = await Puppeteer.LaunchAsync(new LaunchOptions43 {44 Args = new string[] { "--no-sandbox" }45 });
SetContentAsync
Using AI Code Generation
1using System;2using System.Threading.Tasks;3using PuppeteerSharp;4{5 {6 static void Main(string[] args)7 {8 MainAsync().GetAwaiter().GetResult();9 }10 static async Task MainAsync()11 {12 string html = @"<html><head><title>Page Title</title></head><body><p>This is my page.</p></body></html>";13 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);14 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false }))15 using (var page = await browser.NewPageAsync())16 {17 await page.SetContentAsync(html);18 }19 }20 }21}22using System;23using System.Threading.Tasks;24using PuppeteerSharp;25{26 {27 static void Main(string[] args)28 {29 MainAsync().GetAwaiter().GetResult();30 }31 static async Task MainAsync()32 {33 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);34 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false }))35 using (var page = await browser.NewPageAsync())36 {37 }38 }39 }40}41using System;42using System.Threading.Tasks;43using PuppeteerSharp;44{45 {46 static void Main(string[] args)47 {48 MainAsync().GetAwaiter().GetResult();49 }50 static async Task MainAsync()51 {52 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);53 using (var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = false }))54 using (var page = await
SetContentAsync
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 });12 var page = await browser.NewPageAsync();13 await page.SetContentAsync(System.IO.File.ReadAllText("2.html"));14 await page.ScreenshotAsync("1.png");15 await browser.CloseAsync();16 }17 }18}19using System;20using System.Threading.Tasks;21using PuppeteerSharp;22{23 {24 static async Task Main(string[] args)25 {26 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);27 var browser = await Puppeteer.LaunchAsync(new LaunchOptions28 {29 });30 var page = await browser.NewPageAsync();31 await page.SetContentAsync(System.IO.File.ReadAllText("2.html"));32 await page.ScreenshotAsync("1.png");33 await browser.CloseAsync();34 }35 }36}37using System;38using System.Threading.Tasks;39using PuppeteerSharp;40{41 {42 static async Task Main(string[] args)43 {44 await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultRevision);45 var browser = await Puppeteer.LaunchAsync(new LaunchOptions46 {47 });
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!!