我正在尝试使用python&获取页面加载时间selenium通过执行javascript命令performanance.timing
我可以在导航到另一个页面时正确获取值但是如果我从同一页面执行trnasaction / action会将我带到同一页面中的另一个选项卡,则performanance.timing不会更改。 / p>
注意:如果我重新加载页面,我可以更改值
有人可以告诉我如何获得我在网络应用中执行的每个步骤的加载时间。
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()
创建新的“分配”部分导航到页面侧面的另一个选项卡,但时间值不会改变。
图片 -