Bird
0
0

Which code snippet correctly collects these and calculates the total load time from navigationStart to loadEventEnd?

hard📝 Application Q15 of 15
Selenium Python - Advanced Patterns
You want to collect multiple performance metrics in Selenium Python: navigationStart, responseStart, and loadEventEnd. Which code snippet correctly collects these and calculates the total load time from navigationStart to loadEventEnd?
Anav = driver.execute_script('window.performance.timing.navigationStart') resp = driver.execute_script('window.performance.timing.responseStart') load = driver.execute_script('window.performance.timing.loadEventEnd') total_load = resp - nav print(total_load)
Bnav = driver.execute_script('return window.performance.timing.navigationStart;') resp = driver.execute_script('return window.performance.timing.responseStart;') load = driver.execute_script('return window.performance.timing.loadEventEnd;') total_load = load - nav print(total_load)
Cnav = driver.execute_script('return window.performance.navigationStart;') resp = driver.execute_script('return window.performance.responseStart;') load = driver.execute_script('return window.performance.loadEventEnd;') total_load = load - nav print(total_load)
Dnav = driver.execute_script('return window.performance.timing.navigationStart;') resp = driver.execute_script('return window.performance.timing.responseStart;') load = driver.execute_script('return window.performance.timing.loadEventEnd;') total_load = resp - load print(total_load)
Step-by-Step Solution
Solution:
  1. Step 1: Verify JavaScript property paths

    Performance timing properties are under window.performance.timing with return keyword.
  2. Step 2: Check calculation logic

    Total load time is loadEventEnd minus navigationStart, so load - nav is correct.
  3. Final Answer:

    nav = driver.execute_script('return window.performance.timing.navigationStart;') resp = driver.execute_script('return window.performance.timing.responseStart;') load = driver.execute_script('return window.performance.timing.loadEventEnd;') total_load = load - nav print(total_load) -> Option B
  4. Quick Check:

    Correct property path and subtraction order = nav = driver.execute_script('return window.performance.timing.navigationStart;') resp = driver.execute_script('return window.performance.timing.responseStart;') load = driver.execute_script('return window.performance.timing.loadEventEnd;') total_load = load - nav print(total_load) [OK]
Quick Trick: Use full timing path and subtract navigationStart from loadEventEnd [OK]
Common Mistakes:
  • Using wrong property paths without 'timing'
  • Calculating load time with wrong subtraction order
  • Omitting 'return' in execute_script calls

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Selenium Python Quizzes