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() 等等控制着视频的加载,播放和暂停。

相关文章:

  • 2022-12-23
  • 2022-01-26
  • 2022-01-31
  • 2021-12-26
  • 2022-03-10
  • 2021-12-04
  • 2022-02-02
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2021-11-23
  • 2021-06-19
  • 2022-02-02
相关资源
相似解决方案