怎么玩&使用 Selenium 暂停视频? [英] How to play & pause video using Selenium?

查看:46
本文介绍了怎么玩&使用 Selenium 暂停视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我如何使用 Selenium 自动播放/暂停网页上显示的视频..

Can anyone help me with how to automate play/pause video present on the web page using Selenium..

提前致谢...

推荐答案

这非常依赖于浏览器和处理视频的播放器.您很可能需要使用 JavaScript 执行程序.

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

昨晚我和一个朋友讨论了这个问题,他想出了以下示例,使用 Webdriver 的 Python 变体来制作来自 html5demos.com 的演示视频:

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

** 查看 这段 Python 代码(不是我的),它暴露了一个暂停"属性.现在您至少可以验证视频加载、启动和停止.我仍然对使用这种测试持怀疑态度,但至少这是一个开始.

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

这篇关于怎么玩&使用 Selenium 暂停视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆