How to use FrameTree class of PuppeteerSharp package

Best Puppeteer-sharp code snippet using PuppeteerSharp.FrameTree

Run Puppeteer-sharp automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

FrameTree.cs

Source: FrameTree.cs Github

copy
1using System.Collections.Generic;
2using Newtonsoft.Json.Linq;
3using PuppeteerSharp.Helpers;
4using PuppeteerSharp.Messaging;
5
6namespace PuppeteerSharp
7{
8    internal class FrameTree
9    {
10        internal FrameTree()
11        {
12            Childs = new List<FrameTree>();
13        }
14
15        internal FrameTree(JToken frameTree)
16        {
17            var frame = frameTree[MessageKeys.Frame];
18
19            Frame = new FramePayload
20            {
21                Id = frame[MessageKeys.Id].AsString(),
22                ParentId = frame[MessageKeys.ParentId].AsString(),
23                Name = frame[MessageKeys.Name].AsString(),
24                Url = frame[MessageKeys.Url].AsString()
25            };
26
27            Childs = new List<FrameTree>();
28            LoadChilds(this, frameTree);
29        }
30
31        #region Properties
32        internal FramePayload Frame { get; set; }
33        internal List<FrameTree> Childs { get; set; }
34        #endregion
35
36        #region Private Functions
37
38        private void LoadChilds(FrameTree frame, JToken frameTree)
39        {
40            var childFrames = frameTree[MessageKeys.ChildFrames];
41
42            if (childFrames != null)
43            {
44                foreach (var item in childFrames)
45                {
46                    var childFrame = item[MessageKeys.Frame];
47
48                    var newFrame = new FrameTree
49                    {
50                        Frame = new FramePayload
51                        {
52                            Id = childFrame[MessageKeys.Id].AsString(),
53                            ParentId = childFrame[MessageKeys.ParentId].AsString(),
54                            Url = childFrame[MessageKeys.Url].AsString()
55                        }
56                    };
57
58                    if ((item as JObject)[MessageKeys.ChildFrames] != null)
59                    {
60                        LoadChilds(newFrame, item);
61                    }
62
63                    frame.Childs.Add(newFrame);
64                }
65            }
66        }
67
68        #endregion
69    }
70}
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used methods in FrameTree

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)