java - 如何检查 URL 中的视频加载情况?

标签 java selenium video selenium-webdriver

我有一个嵌入了视频的 URL,就像 YouTube URL 一样,我想验证视频是否加载和流式传输 我遇到的困难是我没有 tagname 、 id 或视频元素的任何内容,那么在这种情况下我该如何检查

使用 Selenium 的代码:

public class URLCheck
{
  public static void main(String args[]){
  File file = new File("C:\\Users\\MB0000038\\Desktop\\chromedriver\\chromedriver.exe");
  System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
  WebDriver driver=new ChromeDriver();
  driver.get("https://www.youtube.com/watch?v=FtsrtcagbOQ");  
  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  // JavascriptExecutor js = (JavascriptExecutor) driver;
  // WebElement video = driver.findElement(By.tagName("video"));
  driver.quit();

  }
}

此代码运行良好,但仅打开一个显示视频的 Chrome 选项卡

提前致谢

最佳答案

我已检查您的视频,您可以使用两个标签来验证您的视频。

       driver.get("https://www.youtube.com/watch?v=59rEMnKWoS4");
       driver.manage().window().maximize();    
        WebElement pauseAndPlay = driver.findElement(By.xpath("//button[@class='ytp-play-button ytp-button']"));
        //Get the attribute aria-lable of pauseAndPlay Element which would tells you current state of video(pause/play)
       String videoState=pauseAndPlay.getAttribute("aria-label");
      if(videoState.equalsIgnoreCase("Pause")){
           System.out.println("Video is currently in play state");
           Thread.sleep(3000);
           //pausing my video and checking the current play time
            pauseAndPlay.click();
            Thread.sleep(2000);
           WebElement currentTimeElement=driver.findElement(By.xpath("//span[@class='ytp-time-current']"));
            String currentTime=currentTimeElement.getText();
         if(currentTime!="0:00"){
             System.out.println("my video is getting progressed and currently at:"+currentTime);
          }else{
              System.out.println("my video is not getting played");
          }
    }else if(videoState.equalsIgnoreCase("Play")){

           System.out.println("Video is currently paused");

      }

关于java - 如何检查 URL 中的视频加载情况?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42897800/

相关文章:

java - Android:如何在内存中创建和保存 map View 以供所有 Activity 使用

java - 在 Java 中深度克隆多维数组......?

c# - 尝试通过右键单击 Web 元素打开新选项卡但无法

node.js - fluent-ffmpeg display_aspect_ratio 没有改变

python-3.x - 如何使用python从具有相同属性的多个视频文件中删除两个音频流中的一个特定流?

java - 为什么直接将 Arrays.asList() 分配给 var 时会出现 AssertionError?

java - tomcat无法使用processbuilder启动外部进程

java - Selenium 2.53.0 Firefox 漏洞

javascript - 我正在尝试单击 Selenium Web 驱动程序中的链接以打开对话框

android - 在 Android 上录制视频时添加覆盖