selenium.webdriver 操作H5视频
方法如下,但是play()和pause()方法在浏览器执行正常,通过webdriver好像有问题。
from selenium import webdriver
from time import sleep
with webdriver.Firefox() as driver:
driver.get('https://www.17sucai.com/pins/demo-show?id=34262')
driver.maximize_window()
driver.implicitly_wait(5)
driver.switch_to.frame('iframe')
video = driver.find_element_by_tag_name('video')
# 获取播放文件地址
url = driver.execute_script('return arguments[0].currentSrc;', video)
print(url)
# 播放视频
driver.execute_script('arguments[0].play()', video)
# 保持5S
sleep(5)
# 暂停视频
driver.execute_script('arguments[0].pause()', video)
sleep(1)
# 重新加载视频
driver.execute_script('arguments[0].load()', video)
sleep(3)