3

I'm testing out Selenium's html5 video automation methods, I can't find one to jump a certain amount of time for current location in the video.

driver = webdriver.Firefox()
driver.get("https://www.youtube.com/watch?v=v_I4zqC7GN8")
driver.execute_script('document.getElementsByTagName("video")[0].currentTime=30

allows me to jump to the 30-second time mark.

However, I want to jump 30-seconds from my current time position.

Most tutorials are in java, with some getting really deep into java code -- I'm unfamiliar with Java.

dustinos3
  • 934
  • 3
  • 17
  • 27
Moondra
  • 4,399
  • 9
  • 46
  • 104

1 Answers1

3

You just need to add 30 to the current currentTime value:

document.getElementsByTagName("video")[0].currentTime += 30;
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Wow. That was simple. I noticed that this style attribute below is correlated with how much I move the time cursor. `
    ` (youtube specific). The numbers changes as I hover the mouse over the time bar. Would I be able to directly connect to this element and influence time this way, instead of relying on `executescript` method? I tried, but I kept getting `NosuchElement` exceptions.
    – Moondra Aug 08 '17 at 00:12
  • @Moondra I don't think changing `style` would work and you should do it with "execute script" - even though I have not done this before. Thanks, glad it worked. – alecxe Aug 08 '17 at 02:33