如何检查URL中的视频加载?

时间:2017-03-20 07:16:51

标签: java selenium video selenium-webdriver

我有一个嵌入了视频的网址,就像youtube网址一样,我想验证视频是否加载和流 我遇到的困难是我没有标记名,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标签

提前致谢

1 个答案:

答案 0 :(得分:1)

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

       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");

      }