Hello I'm writing some selenium web scraping code and I want to handle a video player to stop and to play. Basically I handle the player using JS DOM (.play() and .pause()).
The problem is that I'm having an issue scraping multiple videos, like: I scrape and handle a video from url1 and when I go to url2, the video wouldn't be handled
const myFunc = async (driver) => {
await driver.executeScript('document.getElementsByTagName("video")[0].start()')
await driver.executeScript(`document.getElementsByTagName("video")[0].currentTime = ${opening}`)
const actions = driver.actions()
await actions.move(driver.findElement(By.tagName('video'))).sendKeys('f').perform()
const checkEnding = async () => {
setTimeout(async () => {
const currentTime = await driver.executeScript('return document.getElementsByTagName("video")[0].currentTime')
const btns = await driver.findElements(By.xpath('/html/body/center/div[2]/footer/div[1]/div'))
const btnNext = btns[btns.length - 1]
console.log(SERVICE + (await btnNext.getAttribute('onclick')).replace("window.location.href='",''))
console.log(currentTime)
if (currentTime >= ending) {
driver.get(SERVICE + (await btnNext.getAttribute('onclick')).replace("window.location.href='",''))
myFunc(driver)
} else checkEnding()
}, 2E3)
}
checkEnding()
}
I debugged very much this code and I tried also to play it by action click but nothing happens, I also tried to run a test script and it works as well.