How to use AddChildFrame method of PuppeteerSharp.Frame class

Best Puppeteer-sharp code snippet using PuppeteerSharp.Frame.AddChildFrame

Frame.cs

Source:Frame.cs Github

copy

Full Screen

...48 MainWorld = new DOMWorld(FrameManager, this, FrameManager.TimeoutSettings);49 SecondaryWorld = new DOMWorld(FrameManager, this, FrameManager.TimeoutSettings);50 if (parentFrame != null)51 {52 ParentFrame.AddChildFrame(this);53 }54 }55 /// <summary>56 /// Gets the child frames of the this frame57 /// </summary>58 public List<Frame> ChildFrames59 {60 get61 {62 lock (_childFrames)63 {64 return _childFrames.ToList();65 }66 }67 }68 /// <summary>69 /// Gets the frame's name attribute as specified in the tag70 /// If the name is empty, returns the id attribute instead71 /// </summary>72 public string Name { get; private set; }73 /// <summary>74 /// Gets the frame's url75 /// </summary>76 public string Url { get; private set; }77 /// <summary>78 /// Gets a value indicating if the frame is detached or not79 /// </summary>80 public bool Detached { get; set; }81 /// <summary>82 /// Gets the parent frame, if any. Detached frames and main frames return <c>null</c>83 /// </summary>84 public Frame ParentFrame { get; private set; }85 internal FrameManager FrameManager { get; }86 internal string Id { get; set; }87 internal string LoaderId { get; set; }88 internal List<string> LifecycleEvents { get; }89 internal string NavigationURL { get; private set; }90 internal DOMWorld MainWorld { get; }91 internal DOMWorld SecondaryWorld { get; }92 /// <summary>93 /// Navigates to an url94 /// </summary>95 /// <remarks>96 /// <see cref="GoToAsync(string, int?, WaitUntilNavigation[])"/> will throw an error if:97 /// - there's an SSL error (e.g. in case of self-signed certificates).98 /// - target URL is invalid.99 /// - the `timeout` is exceeded during navigation.100 /// - the remote server does not respond or is unreachable.101 /// - the main resource failed to load.102 ///103 /// <see cref="GoToAsync(string, int?, WaitUntilNavigation[])"/> will not throw an error when any valid HTTP status code is returned by the remote server,104 /// including 404 "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling <see cref="Response.Status"/>105 ///106 /// > **NOTE** <see cref="GoToAsync(string, int?, WaitUntilNavigation[])"/> either throws an error or returns a main resource response.107 /// The only exceptions are navigation to `about:blank` or navigation to the same URL with a different hash, which would succeed and return `null`.108 ///109 /// > **NOTE** Headless mode doesn't support navigation to a PDF document. See the <see fref="https://bugs.chromium.org/p/chromium/issues/detail?id=761295">upstream issue</see>.110 /// </remarks>111 /// <param name="url">URL to navigate page to. The url should include scheme, e.g. https://.</param>112 /// <param name="options">Navigation parameters.</param>113 /// <returns>Task which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.</returns>114 /// <seealso cref="GoToAsync(string, int?, WaitUntilNavigation[])"/>115 public Task<Response> GoToAsync(string url, NavigationOptions options) => FrameManager.NavigateFrameAsync(this, url, options);116 /// <summary>117 /// Navigates to an url118 /// </summary>119 /// <param name="url">URL to navigate page to. The url should include scheme, e.g. https://.</param>120 /// <param name="timeout">maximum navigation time in milliseconds. Defaults to 30 seconds. Pass 0121 /// to disable timeout. The default value can be changed by using the <see cref="Page.DefaultNavigationTimeout"/>122 /// property.</param>123 /// <param name="waitUntil">When to consider navigation succeeded, defaults to <see cref="WaitUntilNavigation.Load"/>. Given an array of <see cref="WaitUntilNavigation"/>, navigation is considered to be successful after all events have been fired</param>124 /// <returns>Task which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect</returns>125 public Task<Response> GoToAsync(string url, int? timeout = null, WaitUntilNavigation[] waitUntil = null)126 => GoToAsync(url, new NavigationOptions { Timeout = timeout, WaitUntil = waitUntil });127 /// <summary>128 /// This resolves when the frame navigates to a new URL or reloads.129 /// It is useful for when you run code which will indirectly cause the frame to navigate.130 /// </summary>131 /// <param name="options">navigation options</param>132 /// <returns>Task which resolves to the main resource response.133 /// In case of multiple redirects, the navigation will resolve with the response of the last redirect.134 /// In case of navigation to a different anchor or navigation due to History API usage, the navigation will resolve with `null`.135 /// </returns>136 /// <remarks>137 /// Usage of the <c>History API</c> <see href="https://developer.mozilla.org/en-US/docs/Web/API/History_API"/> to change the URL is considered a navigation138 /// </remarks>139 /// <example>140 /// <code>141 /// <![CDATA[142 /// var navigationTask =frame.page.WaitForNavigationAsync();143 /// await frame.ClickAsync("a.my-link");144 /// await navigationTask;145 /// ]]>146 /// </code>147 /// </example>148 public Task<Response> WaitForNavigationAsync(NavigationOptions options = null) => FrameManager.WaitForFrameNavigationAsync(this, options);149 /// <summary>150 /// Executes a script in browser context151 /// </summary>152 /// <param name="script">Script to be evaluated in browser context</param>153 /// <remarks>154 /// If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.155 /// </remarks>156 /// <returns>Task which resolves to script return value</returns>157 /// <seealso cref="EvaluateFunctionAsync{T}(string, object[])"/>158 /// <seealso cref="Page.EvaluateExpressionAsync{T}(string)"/>159 public Task<JToken> EvaluateExpressionAsync(string script) => MainWorld.EvaluateExpressionAsync(script);160 /// <summary>161 /// Executes a script in browser context162 /// </summary>163 /// <typeparam name="T">The type to deserialize the result to</typeparam>164 /// <param name="script">Script to be evaluated in browser context</param>165 /// <remarks>166 /// If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.167 /// </remarks>168 /// <returns>Task which resolves to script return value</returns>169 /// <seealso cref="EvaluateFunctionAsync{T}(string, object[])"/>170 /// <seealso cref="Page.EvaluateExpressionAsync{T}(string)"/>171 public Task<T> EvaluateExpressionAsync<T>(string script) => MainWorld.EvaluateExpressionAsync<T>(script);172 /// <summary>173 /// Executes a function in browser context174 /// </summary>175 /// <param name="script">Script to be evaluated in browser context</param>176 /// <param name="args">Arguments to pass to script</param>177 /// <remarks>178 /// If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.179 /// <see cref="JSHandle"/> instances can be passed as arguments180 /// </remarks>181 /// <returns>Task which resolves to script return value</returns>182 /// <seealso cref="EvaluateExpressionAsync{T}(string)"/>183 /// <seealso cref="Page.EvaluateFunctionAsync{T}(string, object[])"/>184 public Task<JToken> EvaluateFunctionAsync(string script, params object[] args) => MainWorld.EvaluateFunctionAsync(script, args);185 /// <summary>186 /// Executes a function in browser context187 /// </summary>188 /// <typeparam name="T">The type to deserialize the result to</typeparam>189 /// <param name="script">Script to be evaluated in browser context</param>190 /// <param name="args">Arguments to pass to script</param>191 /// <remarks>192 /// If the script, returns a Promise, then the method would wait for the promise to resolve and return its value.193 /// <see cref="JSHandle"/> instances can be passed as arguments194 /// </remarks>195 /// <returns>Task which resolves to script return value</returns>196 /// <seealso cref="EvaluateExpressionAsync{T}(string)"/>197 /// <seealso cref="Page.EvaluateFunctionAsync{T}(string, object[])"/>198 public Task<T> EvaluateFunctionAsync<T>(string script, params object[] args) => MainWorld.EvaluateFunctionAsync<T>(script, args);199 /// <summary>200 /// Passes an expression to the <see cref="ExecutionContext.EvaluateExpressionHandleAsync(string)"/>, returns a <see cref="Task"/>, then <see cref="ExecutionContext.EvaluateExpressionHandleAsync(string)"/> would wait for the <see cref="Task"/> to resolve and return its value.201 /// </summary>202 /// <example>203 /// <code>204 /// var frame = page.MainFrame;205 /// const handle = Page.MainFrame.EvaluateExpressionHandleAsync("1 + 2");206 /// </code>207 /// </example>208 /// <returns>Resolves to the return value of <paramref name="script"/></returns>209 /// <param name="script">Expression to be evaluated in the <seealso cref="ExecutionContext"/></param>210 public Task<JSHandle> EvaluateExpressionHandleAsync(string script) => MainWorld.EvaluateExpressionHandleAsync(script);211 /// <summary>212 /// Passes a function to the <see cref="ExecutionContext.EvaluateFunctionAsync(string, object[])"/>, returns a <see cref="Task"/>, then <see cref="ExecutionContext.EvaluateFunctionHandleAsync(string, object[])"/> would wait for the <see cref="Task"/> to resolve and return its value.213 /// </summary>214 /// <example>215 /// <code>216 /// var frame = page.MainFrame;217 /// const handle = Page.MainFrame.EvaluateFunctionHandleAsync("() => Promise.resolve(self)");218 /// return handle; // Handle for the global object.219 /// </code>220 /// <see cref="JSHandle"/> instances can be passed as arguments to the <see cref="ExecutionContext.EvaluateFunctionAsync(string, object[])"/>:221 ///222 /// const handle = await Page.MainFrame.EvaluateExpressionHandleAsync("document.body");223 /// const resultHandle = await Page.MainFrame.EvaluateFunctionHandleAsync("body => body.innerHTML", handle);224 /// return await resultHandle.JsonValueAsync(); // prints body's innerHTML225 /// </example>226 /// <returns>Resolves to the return value of <paramref name="function"/></returns>227 /// <param name="function">Function to be evaluated in the <see cref="ExecutionContext"/></param>228 /// <param name="args">Arguments to pass to <paramref name="function"/></param>229 public Task<JSHandle> EvaluateFunctionHandleAsync(string function, params object[] args) => MainWorld.EvaluateFunctionHandleAsync(function, args);230 /// <summary>231 /// Gets the <see cref="ExecutionContext"/> associated with the frame.232 /// </summary>233 /// <returns><see cref="ExecutionContext"/> associated with the frame.</returns>234 public Task<ExecutionContext> GetExecutionContextAsync() => MainWorld.GetExecutionContextAsync();235 /// <summary>236 /// Waits for a selector to be added to the DOM237 /// </summary>238 /// <param name="selector">A selector of an element to wait for</param>239 /// <param name="options">Optional waiting parameters</param>240 /// <returns>A task that resolves when element specified by selector string is added to DOM.241 /// Resolves to `null` if waiting for `hidden: true` and selector is not found in DOM.</returns>242 /// <seealso cref="WaitForXPathAsync(string, WaitForSelectorOptions)"/>243 /// <seealso cref="Page.WaitForSelectorAsync(string, WaitForSelectorOptions)"/>244 /// <exception cref="WaitTaskTimeoutException">If timeout occurred.</exception>245 public async Task<ElementHandle> WaitForSelectorAsync(string selector, WaitForSelectorOptions options = null)246 {247 var handle = await SecondaryWorld.WaitForSelectorAsync(selector, options).ConfigureAwait(false);248 if (handle == null)249 {250 return null;251 }252 var mainExecutionContext = await MainWorld.GetExecutionContextAsync().ConfigureAwait(false);253 var result = await mainExecutionContext.AdoptElementHandleAsync(handle).ConfigureAwait(false);254 await handle.DisposeAsync().ConfigureAwait(false);255 return result;256 }257 /// <summary>258 /// Waits for a selector to be added to the DOM259 /// </summary>260 /// <param name="xpath">A xpath selector of an element to wait for</param>261 /// <param name="options">Optional waiting parameters</param>262 /// <returns>A task which resolves when element specified by xpath string is added to DOM.263 /// Resolves to `null` if waiting for `hidden: true` and xpath is not found in DOM.</returns>264 /// <example>265 /// <code>266 /// <![CDATA[267 /// var browser = await Puppeteer.LaunchAsync(new LaunchOptions());268 /// var page = await browser.NewPageAsync();269 /// string currentURL = null;270 /// page.MainFrame271 /// .WaitForXPathAsync("//img")272 /// .ContinueWith(_ => Console.WriteLine("First URL with image: " + currentURL));273 /// foreach (var current in new[] { "https://example.com", "https://google.com", "https://bbc.com" })274 /// {275 /// currentURL = current;276 /// await page.GoToAsync(currentURL);277 /// }278 /// await browser.CloseAsync();279 /// ]]>280 /// </code>281 /// </example>282 /// <seealso cref="WaitForSelectorAsync(string, WaitForSelectorOptions)"/>283 /// <seealso cref="Page.WaitForXPathAsync(string, WaitForSelectorOptions)"/>284 /// <exception cref="WaitTaskTimeoutException">If timeout occurred.</exception>285 public async Task<ElementHandle> WaitForXPathAsync(string xpath, WaitForSelectorOptions options = null)286 {287 var handle = await SecondaryWorld.WaitForXPathAsync(xpath, options).ConfigureAwait(false);288 if (handle == null)289 {290 return null;291 }292 var mainExecutionContext = await MainWorld.GetExecutionContextAsync().ConfigureAwait(false);293 var result = await mainExecutionContext.AdoptElementHandleAsync(handle).ConfigureAwait(false);294 await handle.DisposeAsync().ConfigureAwait(false);295 return result;296 }297 /// <summary>298 /// Waits for a timeout299 /// </summary>300 /// <param name="milliseconds">The amount of time to wait.</param>301 /// <returns>A task that resolves when after the timeout</returns>302 /// <seealso cref="Page.WaitForTimeoutAsync(int)"/>303 /// <exception cref="WaitTaskTimeoutException">If timeout occurred.</exception>304 public Task WaitForTimeoutAsync(int milliseconds) => Task.Delay(milliseconds);305 /// <summary>306 /// Waits for a function to be evaluated to a truthy value307 /// </summary>308 /// <param name="script">Function to be evaluated in browser context</param>309 /// <param name="options">Optional waiting parameters</param>310 /// <param name="args">Arguments to pass to <c>script</c></param>311 /// <returns>A task that resolves when the <c>script</c> returns a truthy value</returns>312 /// <seealso cref="Page.WaitForFunctionAsync(string, WaitForFunctionOptions, object[])"/>313 /// <exception cref="WaitTaskTimeoutException">If timeout occurred.</exception>314 public Task<JSHandle> WaitForFunctionAsync(string script, WaitForFunctionOptions options, params object[] args)315 {316 if (options == null)317 {318 throw new ArgumentNullException(nameof(options));319 }320 return MainWorld.WaitForFunctionAsync(script, options, args);321 }322 /// <summary>323 /// Waits for an expression to be evaluated to a truthy value324 /// </summary>325 /// <param name="script">Expression to be evaluated in browser context</param>326 /// <param name="options">Optional waiting parameters</param>327 /// <returns>A task that resolves when the <c>script</c> returns a truthy value</returns>328 /// <seealso cref="Page.WaitForExpressionAsync(string, WaitForFunctionOptions)"/>329 /// <exception cref="WaitTaskTimeoutException">If timeout occurred.</exception>330 public Task<JSHandle> WaitForExpressionAsync(string script, WaitForFunctionOptions options)331 {332 if (options == null)333 {334 throw new ArgumentNullException(nameof(options));335 }336 return MainWorld.WaitForExpressionAsync(script, options);337 }338 /// <summary>339 /// Triggers a change and input event once all the provided options have been selected.340 /// If there's no <![CDATA[<select>]]> element matching selector, the method throws an error.341 /// </summary>342 /// <exception cref="SelectorException">If there's no element matching <paramref name="selector"/></exception>343 /// <param name="selector">A selector to query page for</param>344 /// <param name="values">Values of options to select. If the <![CDATA[<select>]]> has the multiple attribute,345 /// all values are considered, otherwise only the first one is taken into account.</param>346 /// <returns>Returns an array of option values that have been successfully selected.</returns>347 /// <seealso cref="Page.SelectAsync(string, string[])"/>348 public Task<string[]> SelectAsync(string selector, params string[] values) => SecondaryWorld.SelectAsync(selector, values);349 /// <summary>350 /// Queries frame for the selector. If there's no such element within the frame, the method will resolve to <c>null</c>.351 /// </summary>352 /// <param name="selector">Selector to query frame for</param>353 /// <returns>Task which resolves to <see cref="ElementHandle"/> pointing to the frame element</returns>354 /// <seealso cref="Page.QuerySelectorAsync(string)"/>355 public Task<ElementHandle> QuerySelectorAsync(string selector) => MainWorld.QuerySelectorAsync(selector);356 /// <summary>357 /// Queries frame for the selector. If no elements match the selector, the return value resolve to <see cref="Array.Empty{T}"/>.358 /// </summary>359 /// <param name="selector">A selector to query frame for</param>360 /// <returns>Task which resolves to ElementHandles pointing to the frame elements</returns>361 /// <seealso cref="Page.QuerySelectorAllAsync(string)"/>362 public Task<ElementHandle[]> QuerySelectorAllAsync(string selector) => MainWorld.QuerySelectorAllAsync(selector);363 /// <summary>364 /// Evaluates the XPath expression365 /// </summary>366 /// <param name="expression">Expression to evaluate <see href="https://developer.mozilla.org/en-US/docs/Web/API/Document/evaluate"/></param>367 /// <returns>Task which resolves to an array of <see cref="ElementHandle"/></returns>368 /// <seealso cref="Page.XPathAsync(string)"/>369 public Task<ElementHandle[]> XPathAsync(string expression) => MainWorld.XPathAsync(expression);370 /// <summary>371 /// Adds a <c><![CDATA[<link rel="stylesheet">]]></c> tag into the page with the desired url or a <c><![CDATA[<link rel="stylesheet">]]></c> tag with the content372 /// </summary>373 /// <param name="options">add style tag options</param>374 /// <returns>Task which resolves to the added tag when the stylesheet's onload fires or when the CSS content was injected into frame</returns>375 /// <seealso cref="Page.AddStyleTagAsync(AddTagOptions)"/>376 /// <seealso cref="Page.AddStyleTagAsync(string)"/>377 [Obsolete("Use AddStyleTagAsync instead")]378 public Task<ElementHandle> AddStyleTag(AddTagOptions options)379 {380 if (options == null)381 {382 throw new ArgumentNullException(nameof(options));383 }384 return MainWorld.AddStyleTagAsync(options);385 }386 /// <summary>387 /// Adds a <c><![CDATA[<script>]]></c> tag into the page with the desired url or content388 /// </summary>389 /// <param name="options">add script tag options</param>390 /// <returns>Task which resolves to the added tag when the script's onload fires or when the script content was injected into frame</returns>391 /// <seealso cref="Page.AddScriptTagAsync(AddTagOptions)"/>392 /// <seealso cref="Page.AddScriptTagAsync(string)"/>393 [Obsolete("Use AddScriptTagAsync instead")]394 public Task<ElementHandle> AddScriptTag(AddTagOptions options)395 {396 if (options == null)397 {398 throw new ArgumentNullException(nameof(options));399 }400 return MainWorld.AddScriptTagAsync(options);401 }402 /// <summary>403 /// Adds a <c><![CDATA[<link rel="stylesheet">]]></c> tag into the page with the desired url or a <c><![CDATA[<link rel="stylesheet">]]></c> tag with the content404 /// </summary>405 /// <param name="options">add style tag options</param>406 /// <returns>Task which resolves to the added tag when the stylesheet's onload fires or when the CSS content was injected into frame</returns>407 /// <seealso cref="Page.AddStyleTagAsync(AddTagOptions)"/>408 /// <seealso cref="Page.AddStyleTagAsync(string)"/>409 public Task<ElementHandle> AddStyleTagAsync(AddTagOptions options)410 {411 if (options == null)412 {413 throw new ArgumentNullException(nameof(options));414 }415 return MainWorld.AddStyleTagAsync(options);416 }417 /// <summary>418 /// Adds a <c><![CDATA[<script>]]></c> tag into the page with the desired url or content419 /// </summary>420 /// <param name="options">add script tag options</param>421 /// <returns>Task which resolves to the added tag when the script's onload fires or when the script content was injected into frame</returns>422 /// <seealso cref="Page.AddScriptTagAsync(AddTagOptions)"/>423 /// <seealso cref="Page.AddScriptTagAsync(string)"/>424 public Task<ElementHandle> AddScriptTagAsync(AddTagOptions options)425 {426 if (options == null)427 {428 throw new ArgumentNullException(nameof(options));429 }430 return MainWorld.AddScriptTagAsync(options);431 }432 /// <summary>433 /// Gets the full HTML contents of the page, including the doctype.434 /// </summary>435 /// <returns>Task which resolves to the HTML content.</returns>436 /// <seealso cref="Page.GetContentAsync"/>437 public Task<string> GetContentAsync() => SecondaryWorld.GetContentAsync();438 /// <summary>439 /// Sets the HTML markup to the page440 /// </summary>441 /// <param name="html">HTML markup to assign to the page.</param>442 /// <param name="options">The options</param>443 /// <returns>Task.</returns>444 /// <seealso cref="Page.SetContentAsync(string, NavigationOptions)"/>445 public Task SetContentAsync(string html, NavigationOptions options = null)446 => SecondaryWorld.SetContentAsync(html, options);447 /// <summary>448 /// Returns page's title449 /// </summary>450 /// <returns>page's title</returns>451 /// <seealso cref="Page.GetTitleAsync"/>452 public Task<string> GetTitleAsync() => SecondaryWorld.GetTitleAsync();453 /// <summary>454 /// Fetches an element with <paramref name="selector"/>, scrolls it into view if needed, and then uses <see cref="Page.Mouse"/> to click in the center of the element.455 /// </summary>456 /// <param name="selector">A selector to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked.</param>457 /// <param name="options">click options</param>458 /// <exception cref="SelectorException">If there's no element matching <paramref name="selector"/></exception>459 /// <returns>Task which resolves when the element matching <paramref name="selector"/> is successfully clicked</returns>460 public Task ClickAsync(string selector, ClickOptions options = null)461 => SecondaryWorld.ClickAsync(selector, options);462 /// <summary>463 /// Fetches an element with <paramref name="selector"/>, scrolls it into view if needed, and then uses <see cref="Page.Mouse"/> to hover over the center of the element.464 /// </summary>465 /// <param name="selector">A selector to search for element to hover. If there are multiple elements satisfying the selector, the first will be hovered.</param>466 /// <exception cref="SelectorException">If there's no element matching <paramref name="selector"/></exception>467 /// <returns>Task which resolves when the element matching <paramref name="selector"/> is successfully hovered</returns>468 public Task HoverAsync(string selector) => SecondaryWorld.HoverAsync(selector);469 /// <summary>470 /// Fetches an element with <paramref name="selector"/> and focuses it471 /// </summary>472 /// <param name="selector">A selector to search for element to focus. If there are multiple elements satisfying the selector, the first will be focused.</param>473 /// <exception cref="SelectorException">If there's no element matching <paramref name="selector"/></exception>474 /// <returns>Task which resolves when the element matching <paramref name="selector"/> is successfully focused</returns>475 public Task FocusAsync(string selector) => SecondaryWorld.FocusAsync(selector);476 /// <summary>477 /// Sends a <c>keydown</c>, <c>keypress</c>/<c>input</c>, and <c>keyup</c> event for each character in the text.478 /// </summary>479 /// <param name="selector">A selector of an element to type into. If there are multiple elements satisfying the selector, the first will be used.</param>480 /// <param name="text">A text to type into a focused element</param>481 /// <param name="options">The options to apply to the type operation.</param>482 /// <exception cref="SelectorException">If there's no element matching <paramref name="selector"/></exception>483 /// <remarks>484 /// To press a special key, like <c>Control</c> or <c>ArrowDown</c> use <see cref="Keyboard.PressAsync(string, PressOptions)"/>485 /// </remarks>486 /// <example>487 /// <code>488 /// await frame.TypeAsync("#mytextarea", "Hello"); // Types instantly489 /// await frame.TypeAsync("#mytextarea", "World", new TypeOptions { Delay = 100 }); // Types slower, like a user490 /// </code>491 /// </example>492 /// <returns>Task</returns>493 public Task TypeAsync(string selector, string text, TypeOptions options = null)494 => SecondaryWorld.TypeAsync(selector, text, options);495 internal void AddChildFrame(Frame frame)496 {497 lock (_childFrames)498 {499 _childFrames.Add(frame);500 }501 }502 internal void RemoveChildFrame(Frame frame)503 {504 lock (_childFrames)505 {506 _childFrames.Remove(frame);507 }508 }509 internal void OnLoadingStopped()...

Full Screen

Full Screen

AddChildFrame

Using AI Code Generation

copy

Full Screen

1var page = await browser.NewPageAsync();2var frame = await page.AddChildFrameAsync(new PuppeteerSharp.FrameOptions3{4});5await frame.EvaluateExpressionAsync("document.body.innerHTML = '<h1>Hi</h1>'");6await page.ScreenshotAsync("5.png");7var page = await browser.NewPageAsync();8var frame = await page.AddChildFrameAsync(new PuppeteerSharp.FrameOptions9{10});11await frame.AddScriptTagAsync(new PuppeteerSharp.AddTagOptions12{13});14await page.ScreenshotAsync("6.png");15var page = await browser.NewPageAsync();16var frame = await page.AddChildFrameAsync(new PuppeteerSharp.FrameOptions17{18});19await frame.AddStyleTagAsync(new PuppeteerSharp.AddTagOptions20{21 Content = "body { background-color: red; }"22});23await page.ScreenshotAsync("7.png");24var page = await browser.NewPageAsync();25var frame = await page.AddChildFrameAsync(new PuppeteerSharp.FrameOptions26{27});28await frame.AddStyleTagAsync(new PuppeteerSharp.AddTagOptions29{30 Content = "body { background-color: red; }"31});32await page.ScreenshotAsync("8.png");33var page = await browser.NewPageAsync();34var frame = await page.AddChildFrameAsync(new PuppeteerSharp.FrameOptions35{

Full Screen

Full Screen

AddChildFrame

Using AI Code Generation

copy

Full Screen

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 var options = new LaunchOptions { Headless = false };13 using (var browser = await Puppeteer.LaunchAsync(options))14 using (var page = await browser.NewPageAsync())15 {16 var frame = page.MainFrame;17 Console.WriteLine("Child frame name: " + childFrame.Name);18 Console.WriteLine("Child frame URL: " + childFrame.Url);19 Console.WriteLine("Child frame parent frame: " + childFrame.ParentFrame.Name);20 await frame.RemoveChildFrameAsync(childFrame);21 }22 }23 }24}

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful