I am trying to use selenium get asynchronous elements(MathJax equation) loading time.
I try to write a python-selenium script to record the loading time of my website, but my website contains a lot of equation which converted by Mathjax asynchronous, so that I cannot record it correctly.
I try to use "performance.timing" to record the loading time first, but it only can provide me 'load time'.
from selenium import webdriver
source = "url"
driver = webdriver.Chrome()
driver.get(source)
navigationStart = driver.execute_script("return window.performance.timing.navigationStart")
loadEventEnd = driver.execute_script("return window.performance.timing.loadEventEnd")
load_time = loadEventEnd - navigationStart
Then, I try to locate the ID of "MathJax" and wait until one mathjax element (e.g "MathJax-Element-1-Frame") is loaded
from selenium import webdriver
import time
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
source = "url"
driver = webdriver.Chrome()
begin = time.time()
driver.get(source)
locator = (By.ID, 'MathJax-Element-1-Frame')
WebDriverWait(driver, 20, 0.5).until(EC.presence_of_element_located(locator))
end = time.time()
finish_time = end - begin
But the time is not absolutely correct.