簡體   English   中英

Selenium Webdriver:單擊視頻控件播放按鈕

[英]Selenium Webdriver: Click video control play button

如何在此頁面上的視頻的視頻控件中單擊播放按鈕? http://prolifiq.com/inside-prolifiq/tiles/invite/

以下是頁面來源。 我確實看到了看起來像JavaScript的“播放暫停”控件,但不確定如何單擊它。

<div id="videoModal" class="reveal-modal expand open" style="display: block; opacity: 1; visibility: visible; top: 100px;">
<video id="wp_mep_1" width="709" height="540" preload="none" controls="controls" poster="http://prolifiq.com/wp-content/themes/prolifiq/img/bgr-video.png">
<source type="video/mp4" src="http://prolifiq.com/wp-content/themes/prolifiq/videos/Prolifiq-Invite.mp4"></source>
<source type="video/webm" src="http://prolifiq.com/wp-content/themes/prolifiq/videos/Prolifiq-Invite.webm"></source>
<object width="709" height="540" data="http://prolifiq.com/wp-content/plugins/media-element-html5-video-and-audio-player/mediaelement/flashmediaelement.swf" type="application/x-shockwave-flash">
</video>
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#wp_mep_1').mediaelementplayer({
m:1
,features: ['playpause','current','progress','duration','volume','tracks','fullscreen']
});
});
</script>
<a class="close-reveal-modal">×</a>
</div>

我可以使用xpath單擊播放器右上角的“ x”按鈕來關閉視頻。

下面是我的代碼:

import java.util.List;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;

import org.junit.*;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class prolifictestscript {
  private WebDriver driver;
  private String baseUrl;
  private boolean acceptNextAlert = true;
  private StringBuffer verificationErrors = new StringBuffer();

  @Before
  public void setUp() throws Exception {
    driver = new FirefoxDriver();
    baseUrl = "http://prolifiq.com";
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
  }

  @Test
  public void testProlifictestscript() throws Exception {
    driver.get(baseUrl + "/");
    driver.findElement(By.xpath(".//*[@id='menu-item-1905']/a")).click();//click menu
    driver.findElement(By.linkText("Tiles")).click();//click sub menu
    driver.findElement(By.xpath("html/body/section[1]/div[2]/ul/li[5]/a")).click();//click invite tile
    List<WebElement> downloadHeader = driver.findElements(By.xpath("//h1[text() = 'Invite']"));//verify h1 invite exists
    if(downloadHeader.size() > 0)
    {
        System.out.println("Found h1 header Invite");
    }

    driver.findElement(By.xpath("html/body/section[1]/div/a/img")).click();//click movie box

    //driver.findElement(By.xpath(".//*[@id='videoModal']")).click();//.//*[@id='videoModal']//not working
    Thread.sleep(49000);//wait 49 seconds for video to end
    driver.findElement(By.xpath(".//*[@id='videoModal']/a")).click();//click x button
  }

  @After
  public void tearDown() throws Exception {
    //driver.quit();
    String verificationErrorString = verificationErrors.toString();
    if (!"".equals(verificationErrorString)) {
      fail(verificationErrorString);
    }
  }

  private boolean isElementPresent(By by) {
    try {
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
      return false;
    }
  }

  private boolean isAlertPresent() {
    try {
      driver.switchTo().alert();
      return true;
    } catch (NoAlertPresentException e) {
      return false;
    }
  }

  private String closeAlertAndGetItsText() {
    try {
      Alert alert = driver.switchTo().alert();
      String alertText = alert.getText();
      if (acceptNextAlert) {
        alert.accept();
      } else {
        alert.dismiss();
      }
      return alertText;
    } finally {
      acceptNextAlert = true;
    }
  }
}

使用Javascript做到這一點,它在Flash Player上運行良好,此處提供了有關可用標簽HTML音頻/視頻DOM參考的一些信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM