HTML5定义了一个新的元素<video>,指定了一个标准的的方式来嵌入电影片段,IE9+,Firefox,Opera,Chrome都已经支持。下面是一个简单的例子,实现视频的播放和暂停。
package com.selenium.api;
import static org.junit.Assert.*;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class HTML5 {
@Test
public void testHTML5Video() throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.get("http://videojs.com/");
WebElement video = driver.findElement(By.id("preview-player_html5_api"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
//获得视频的URL
String source = (String) jse.executeScript("ret