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

查看:358
本文介绍了怎么玩&使用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天全站免登陆