selenium webdriver處理HTML5 的視頻播放


import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class Video {
      public static void main(String args[]) throws InterruptedException {
            WebDriver driver = new ChromeDriver();
            driver.get("http://videojs.com/");
            WebElement video = driver.findElement(By.id("home_video"));
            JavascriptExecutor jse = (JavascriptExecutor)driver;
            //獲得視屏的URL
            jse.executeScript("return arguments[0].currentSrc;",video);
            //播放視屏,播放15 秒鍾
            jse.executeScript("return arguments[0].play()", video);
            Thread.sleep(15000);
            //暫停視屏
            jse.executeScript("arguments[0].pause()", video);
            driver.quit();
       }
}

JavaScript 函數有個內置的對象arguments 對象。argument 對象包含了函數調用的參數數組。[0]表示取對象的第1 個值。

currentSrc 熟悉返回當前音頻/視頻的URL。如果未設置音頻/視頻,則返回空字符串。
load()、play()、pause() 等等控制着視頻的加載,播放和暫停。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM