How to play & pause video using Selenium? How to play & pause video using Selenium? selenium selenium

How to play & pause video using Selenium?


This is extremely dependent on the browser and the player handling the video. You'll need to use the JavaScript executor, most likely.

I was discussing this last night with a pal and he came up with the following example using the Python variant of Webdriver for a demo video from html5demos.com:

driver = webdriver.Firefox()driver.get("http://html5demos.com/video")driver.execute_script('document.getElementsByTagName("video")[0].play()')

You can also "pause" where the "play" is used.

There's a larger question here: what are you actually trying to verify? That simply playing and pausing doesn't throw any errors? Make sure you know what you're validating and that it makes sense to actually work to automate the video test versus just leaving that particular use case to a manual test. (Though you could use the above script to get you to that point!)

** EDIT: Check out this bit of Python code (not mine) which exposes a "Paused" property. Now you could at least validate video loads, starts, and can be stopped. I'm still skeptical of the use of this sort of test, but at least it's a start.


By Using FlashObjectwebDriver !

Now what is FlashObjectWebDriver ?

FlashObjectWebDriver is an interface under Webdriver Library.FlashObjectWebDriver has a Method called : callFlashObjectcallFlashObject method can be over loaded using arguments ie.callFlashObject(“Play”) : For Playing the FlashcallFlashObject(“Pause”) : For Pausing the FlashcallFlashObject(“Previous”) : For playing previous Flash videocallFlashObject(“next”) : For playing next Flash videocallFlashObject(“SetVariable”, “/:Message) : For displaying the message .Implementation :

FlashObjectWebDriver flashApp = new FlashObjectWebDriver(driver, "myFlashMovie");           // Pass the URL of video            driver.get("http://demo.guru99.com/flash-testing.html");                Thread.sleep(5000);         flashApp.callFlashObject("Play");               Thread.sleep(5000);         flashApp.callFlashObject("StopPlay");               Thread.sleep(5000);         flashApp.callFlashObject("SetVariable","/:message","Flash testing using selenium Webdriver");    System.out.println(flashApp.callFlashObject("GetVariable","/:message"));