How to take a video of what's happening in selenium How to take a video of what's happening in selenium selenium selenium

How to take a video of what's happening in selenium


WebDriver has 3 methods which could be useful for you, get_screenshot_as_png, get_screenshot_as_base64 and get_screenshot_as_file. With that you can took screenshots in background thread and use OpenCV and PIL to generate a video file from the results.

If you don't want to introduce new dependencies you also dump screenshots to files and in the end use ffmpeg to generate a video as well.


I did not try this, but it should work anyway. Your code terminates the ffmpeg process. The software cannot finish the video file. The following code should end the process gracefully:

self.videoRecording.send_signal(subprocess.CTRL_C_EVENT)self.videoRecording.wait()

You will need additional parameters for your popen statement. Please refer to https://docs.python.org/3.7/library/subprocess.html.

import subprocess...Popen(cmd, creationflags = subprocess.CREATE_NEW_PROCESS_GROUP)

You can also repair corrupt video files with ffmpeg:

ffmpeg -err_detect ignore_err -i screen-capture.mp4 -c copy video_fixed-screen-capture.mp4