I would like in interval to track video play progress in a HTML video.
Based on the tutorial, the HTML video DOM timeupdate
event can be achieved by something like below:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import time
chrome_options = webdriver.ChromeOptions()
browser = webdriver.Chrome(executable_path=r"\Browsers\chromedriver.exe",
options=chrome_options)
browser.get("https://www.youtube.com/watch?v=nXbfZL5kttM")
WebDriverWait(browser, 70).until(EC.element_to_be_clickable(
(By.XPATH, "//button[@aria-label='Play']"))).click()
javascript_to_execute = ' return document.getElementById("ytplayer").currentTime();'
for x in range(0, 2):
time_current = browser.execute_script(javascript_to_execute)
print(time_current)
time.sleep(1)
However, I got the following error
Message: javascript error: Cannot read property 'currentTime' of null
May I know where did I do wrong. Appreciate for any hint or help. Thanks in advance