Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to block or set HTML5 Videos to autoplay using Selenium and Python?

I am writing a script and want to be able to set autoplay for any HTML5 Stream or Video. If even better, I would like to block or remove it temporarily from the site I am on. I will provide the inspected element as well.

If no one knows the above, is there way I can block a certain video id or class

<video id="still_video_object_html5_api" class="vjs-tech"

These are also the scripts that are unchanging to the HTML5 Live Stream

webkit-playsinline="" playsinline="" autoplay="" tabindex="-1"
type="application/x-mpegURL"></video>

I am using: Python, Selenium Webdriver, & Chrome on Windows 10

like image 486
Otaku Wiz Avatar asked Sep 20 '25 06:09

Otaku Wiz


1 Answers

Tested with Chrome 67 and the C# version of the ChromeDriver, here's the code that allowed me to have YouTube videos autoplayed (whereas the default behaviour since Chrome 66 is to disable autoplay) :

var options = new ChromeOptions();
options.AddArgument("--autoplay-policy=no-user-gesture-required");
IWebDriver browserDriver = new ChromeDriver(AppContext.BaseDirectory, options);

The Python API certainly has equivalent to the AddArgument(string) method.

like image 106
kall2sollies Avatar answered Sep 21 '25 23:09

kall2sollies