【问题标题】:Selenium web driver unable to automatically play videoSelenium Web 驱动程序无法自动播放视频
【发布时间】:2020-04-04 01:05:54
【问题描述】:

我正在尝试测试我网站上的视频播放器是否可以正常工作。 我试过了,但视频播放器没有开始播放视频。

driver.get("https://www.w3schools.com/html/html5_video.asp");
//sleep for the page to entirely load
Thread.sleep(10000L);
String videoPlayerPath = "document.getElementById(\"video1\")";
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript(videoPlayerPath + ".play()");

document.getElementById("video1").play() 在浏览器控制台上工作,但我无法通过 Selenium 让它工作

【问题讨论】:

    标签: java selenium selenium-chromedriver


    【解决方案1】:

    使用WebDriverWait而不是Thread.sleep来加载内容并像这样在一行中使用JS部分

    js.executeScript("document.getElementById('video1').play();");
    

    【讨论】:

    • 我在控制台上没有看到任何可以帮助调试的错误。
    • 如果发生任何异常,则使用 try-catch 整个程序
    猜你喜欢
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    • 2015-09-17
    • 2022-01-19
    • 2017-07-09
    • 1970-01-01
    • 1970-01-01
    • 2016-08-11
    相关资源
    最近更新 更多