【问题标题】:Jumping a certain amount of time in html5 video using Selenium使用 Selenium 在 html5 视频中跳跃一定时间
【发布时间】:2017-08-07 23:19:09
【问题描述】:

我正在测试 Selenium 的 html5 视频自动化方法,我找不到一个可以为视频中的当前位置跳转一定时间的方法。

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

允许我跳转到 30 秒的时间标记。

但是,我想从当前时间位置跳 30 秒。

大多数教程都是用 Java 编写的,其中一些对 Java 代码非常深入——我不熟悉 Java。

【问题讨论】:

    标签: python selenium-webdriver


    【解决方案1】:

    您只需将30 添加到当前的currentTime 值:

    document.getElementsByTagName("video")[0].currentTime += 30;
    

    【讨论】:

    • 哇。那很简单。我注意到下面的这个样式属性与我移动时间光标的程度相关。 <div class ="ytp-tooltip ytp-bottom" style "max-width: 300px; top: 405px; left: 142.5px; display: none;" data-layer ="4">(特定于 youtube)。当我将鼠标悬停在时间栏上时,数字会发生变化。我可以直接连接到这个元素并以这种方式影响时间,而不是依赖executescript 方法吗?我试过了,但我不断收到NosuchElement 异常。
    • @Moondra 我不认为改变style 会起作用,你应该用“执行脚本”来做——即使我以前没有这样做过。谢谢,很高兴它成功了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多