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("return arguments[0].currentSrc;",video);
assertEquals("http://vjs.zencdn.net/v/oceans.mp4", source);
//播放视频
jse.executeScript("return arguments[0].play()", video);
Thread.sleep(5000);
//暂停视频
jse.executeScript("arguments[0].pause()", video);
//driver.quit();
}
}
转载于:https://my.oschina.net/wiley2/blog/606901