Selenium网络驱动无法自动播放视频。

huangapple 未分类评论41阅读模式
英文:

Selenium web driver unable to automatically play video

问题

Sure, here is the translated version of the provided content:

我正在尝试测试我的网站上的视频播放器是否正常工作。
我尝试了以下代码,但视频播放器无法开始播放视频。

driver.get("https://www.w3schools.com/html/html5_video.asp");
//等待页面完全加载
Thread.sleep(10000L);
String videoPlayerPath = "document.getElementById(\"video1\")";
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript(videoPlayerPath + ".play()");

在浏览器控制台上,document.getElementById("video1").play() 是有效的,但是我无法通过 Selenium 使其正常工作。

英文:

I'm trying to test if the video player on my website works.
I tried this, but the video player does not start playing the video.

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() works on the browser console, but I'm not able to get it working via Selenium

答案1

得分: 0

使用WebDriverWait代替Thread.sleep来加载内容,并且像这样一行代码中使用JS部分:

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

use WebDriverWaitinstead of Thread.sleep to load the content and use the JS part in one line like this

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

huangapple
  • 本文由 发表于 2020年4月4日 00:59:07
  • 转载请务必保留本文链接:https://java.coder-hub.com/61016832.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定