[英]Performanance.timing values not changing for multiple requests in same page for page load time using python selenium
我正在嘗試通過執行 javascript 命令performanance.timing
使用 python 和 selenium 獲取頁面加載時間
當導航到另一個頁面時,我能夠正確獲取值,但如果我從同一頁面執行一個交易/操作,這將帶我到同一頁面中的另一個選項卡,則 performanance.timing 不會改變。
注意:如果我重新加載頁面,我可以更改值
有人可以告訴我如何獲得我在 web 應用程序中執行的每個步驟的加載時間。
python selenium 腳本:
from selenium import webdriver
driver = webdriver.Firefox()
driver.implicitly_wait(40)
########### Home Page #################
driver.get("http://app.edulastic.com")
navigationStart = driver.execute_script("return window.performance.timing.navigationStart")
responseStart = driver.execute_script("return window.performance.timing.responseStart")
domComplete = driver.execute_script("return window.performance.timing.domComplete")
loadStart = driver.execute_script("return window.performance.timing.domInteractive")
loadend = driver.execute_script("return window.performance.timing.navigationStart")
backendPerformance = responseStart - navigationStart
frontendPerformance = domComplete - responseStart
loadingTime=loadStart-loadend
print ("Back End Homepage: %s" % backendPerformance)
print ("Front End Homepage: %s" % frontendPerformance)
print("loading time : %s" %loadingTime)
#################### Dashboard ##################
driver.find_element_by_id('login-email').send_keys("*****@gmail.com")
driver.find_element_by_id("login-password").send_keys("******")
driver.find_element_by_id("signIn").click()
driver.find_element_by_link_text("Create New Assignment")
navigationStart = driver.execute_script("return window.performance.timing.navigationStart")
responseStart = driver.execute_script("return window.performance.timing.responseStart")
domComplete = driver.execute_script("return window.performance.timing.domComplete")
domLoading = driver.execute_script("return window.performance.timing.domLoading")
loadStart = driver.execute_script("return window.performance.timing.domInteractive")
loadend = driver.execute_script("return window.performance.timing.navigationStart")
backendPerformance = responseStart - navigationStart
frontendPerformance = domComplete - responseStart
loadingTime=loadStart-loadend
#print("time converted ... %s" %time.strftime("%SSSS", time.gmtime(domLoading)))
print ("Back End Dashboard: %s" % backendPerformance)
print ("Front End Dashboard: %s" % frontendPerformance)
print("loading time : %s" %loadingTime)
#print("dom laoding time :%s" %domLoading)
########## create new assignment #########
driver.find_element_by_link_text("Create New Assignment").click()
print(driver.find_element_by_id("create-assessment-with-val").is_displayed())
loadStart = driver.execute_script("return window.performance.timing.domInteractive")
loadend = driver.execute_script("return window.performance.timing.navigationStart")
loadingTime = loadStart-loadend
print("loading time : %s" %loadingTime)
driver.quit()
創建新的分配部分導航到頁面一側的另一個選項卡,但時間值不會改變。
圖片 -
我知道問題已經過去 5 年了,但我今天才發現問題出在哪里。
"return window.performance.timing"
function 從瀏覽器控制台獲取信息。 如果您在同一個 window 中使用同一個 function 兩次,它每次都會返回相同的數字,因為它是仍然打開的同一個窗口。
如果你想每次都獲得新的性能時序,你只需預先用driver.refresh()
刷新 window
刷新后開始
navigationStart = driver.execute_script("return window.performance.timing.navigationStart")
responseStart = driver.execute_script("return window.performance.timing.responseStart")
然后像以前一樣繼續執行代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.