I am writing a PowerShell script to log into a website, load a database entry, add a note, then log off. After the website finishes loading, I want to know how long it takes me to open the "notes" part, enter the note, and save it.
This works:
Add-Type -Path "<path to web driver>\WebDriver.dll"
$options = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$options.AddArgument("--disable-gpu")
$driver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($options)
... load browser, navigate to URL, and log in...
$startTime = $driver.ExecuteScript("return performance.timing.navigationStart")
... do some work ...
$endTime = $driver.ExecuteScript("return window.performance.timing.domComplete")
$duration = $endTime - $startTime
That's fine, but per https://developer.mozilla.org/en-US/docs/Web/API/PerformanceTiming, this feature is deprecated. PerformanceNavigationTiming seems like it ought to work, but I do not understand how to invoke it.
Using:
$startTime = $driver.ExecuteScript("return performanceEntry.PerformanceEntry.startTime")
Returns:
Exception calling "ExecuteScript" with "1" argument(s): "javascript error: performanceEntry is not defined
(Session info: chrome=109.0.5414.75)"
While using:
$startTime = $driver.ExecuteScript("return PerformanceEntry.startTime")
Does not return anything (no error and no value).
I know I could use [system.diagnostics.stopwatch]::startNew()
, but I would prefer to do this in the browser. Anyone know how that is accomplished?