Getting Current Video Tag Url With Selenium
I'm trying to get the current html5 video tag URL using selenium (with python bindings): from selenium import webdriver driver = webdriver.Chrome() driver.get('https://www.youtub
Solution 1:
According to the W3 video tag specification:
The currentSrc DOM attribute is initially the empty string. Its value is changed by the resource selection algorithm.
Which explains the behavior described in the question. This also means that to get the currentSrc
value reliably, we need to wait until the media resource has it defined.
Subscribing to the loadstart
media event through execute_async_script()
did the trick:
driver.set_script_timeout(10)
url = driver.execute_async_script("""
var video = arguments[0],
callback = arguments[arguments.length - 1];
video.addEventListener('loadstart', listener);
function listener() {
callback(video.currentSrc);
};
""", video)
print(url)
Post a Comment for "Getting Current Video Tag Url With Selenium"