0

I'm using Selenium Webdriver and am working with IE11.
I'd like to access the window performance resources from an HTML page.
From chrome I can do that easily with

IJavaScriptExecutor js = _webDriver as IJavaScriptExecutor;
ReadOnlyCollection<object> rList =  ReadOnlyCollection<object>)js.ExecuteScript("return window.performance.getEntriesByType(\"resource\")");

and then a simple String object dictionary cast lets me get the details.

BUT the same code doesn't work for IE. There I am forced to cast the contents of what js is returning to a ReadOnlyCollection<IWebElement> - which is obviously not containing any of the info I want it to.
Does anyone know what I ought to do to get the real info back?

Eugene S
  • 6,709
  • 8
  • 57
  • 91
SlightlyKosumi
  • 701
  • 2
  • 8
  • 24

2 Answers2

0

Well I found an answer of sorts Basically I can query with strings like this to find the array description and access individual items.

"return window.performance.getEntriesByType(\"resource\").length"
"return window.performance.getEntriesByType(\"resource\")[0].name"

Not really the solution I expected, but it works

SlightlyKosumi
  • 701
  • 2
  • 8
  • 24
0

Edit: I'm gonna leave my other answer because of how dumb I am. Here's what I'm using now.

        var resourceJson = ieDriver.ExecuteScript("var resourceTimings = window.performance.getEntriesByType(\"resource\");return JSON.stringify(resourceTimings)");
        var resourceTimings = JsonConvert.DeserializeObject<System.Collections.ObjectModel.ReadOnlyCollection<object>>(resourceJson.ToString());

I'm stuck in the same boat, this is the best I could do:

        var resNames = ieDriver.ExecuteScript("var keys = [];for(var key in window.performance.getEntriesByType(\"resource\")){keys.push(key);} return keys;");
        Dictionary<string, Dictionary<string, object>> resTimings = new Dictionary<string, Dictionary<string, object>>();
        foreach (string name in (System.Collections.ObjectModel.ReadOnlyCollection<object>)resNames)
        {
            var resource = new Dictionary<string, object>();
            var resProperties = ieDriver.ExecuteScript(string.Format("var keys = [];for(var key in window.performance.getEntriesByType(\"resource\")[{0}]){{keys.push(key);}} return keys;", name));
            foreach (string property in (System.Collections.ObjectModel.ReadOnlyCollection<object>)resProperties)
            {
                resource.Add(property, ieDriver.ExecuteScript(string.Format("return window.performance.getEntriesByType(\"resource\")[{0}].{1};", name, property)));
            }
            resTimings.Add(name, resource);
        }

This works, but seems to take way too long. I'm sure there are a lot of optimizations to make. Don't know much js, but it seems it might go faster to offload the work there.

Vince
  • 36
  • 3