简体   繁体   中英

Selenium Webdriver: Click video control play button

How can I click the play button within video controls on the video located on this page? http://prolifiq.com/inside-prolifiq/tiles/invite/

Below is the page source. I do see what looks like a javascript 'playpause' control but I'm not sure how to click it.

<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>

I am able close the video by clicking the "x" button in the player's upper right using xpath.

Below is my code:

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参考的一些信息

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM