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?
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.