0

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?

StackExchangeGuy
  • 741
  • 16
  • 36

1 Answers1

0

I don't have a performanceEntry in Chrome or FF. PerformanceEntry is a type.

This might do what you want to get an instance of PerformanceNavigationTiming:

performance.getEntriesByType("navigation")[0]

So your script would be:

$startTime = $driver.ExecuteScript('return performance.getEntriesByType("navigation")[0].startTime')
FSCKur
  • 920
  • 7
  • 16
  • Looks like `$driver.ExecuteScript("performance.getEntriesByType("navigation")[0]")` does not return anything (errors or otherwise). Note that, in the PowerShell host, I have to escape the quotes around "navigation" with backticks. – StackExchangeGuy Feb 02 '23 at 14:29
  • Fixed the quotes, thx. Apologies, I don't have a Selenium install handy to test in Selenium - this worked in the browser console. Hopefully someone can get to the answer from here. – FSCKur Feb 02 '23 at 18:34