我正在尝试播放以下网站的视频(使用 JUnit)- Day01。 http://www.itelearn.com/live-training/security-testing-live-training 我想要实现的是在播放视频后我会截屏以证明视频播放正常。单击 Day01 视频后,它会在新窗口中打开 - 当我查看代码时,我意识到他们使用了 iFrame。我可以关闭此视频窗口,但无法播放/暂停此视频。
要关闭我使用代码的视频-- WebDriverWait wait = new WebDriverWait(driver, 20); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(xPath))).click();
我是测试新手,请帮助我。
最佳答案
那么你切换到 iframe 了吗?
尝试以下未经测试的Java代码,请注意,这里的逻辑很简单,你通过xpath或css选择器找到iframe元素,然后切换到它,然后点击。然而,自动化播放器可能并不那么容易和稳定。如果可以,请提供反馈,谢谢。
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement playerIframe = wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#sb-player iframe")));
driver.switchTo().frame(playerIframe);
// make sure you have html5 video loaded, instead of flash
// otherwise Selenium won't find a thing
driver.findElement(By.cssSelector("svg.ytp-cued-icon")).click();
要默认加载 HTML5,请参阅 this page或加载扩展 HTML5 Video for YouTube启动 Selenium 时。
关于java - 使用带有 Java 的 Selenium WebDriver 播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17627554/