Reputation: 41
I did not get a specific chrome option to work fine, when started chrome per python selenium webdriver script.
The goal is to start chrome in a python selenium script with a fake webcam, which plays a video file.
The problematic options are "use-file-for-fake-video-capture" combined with "use-fake-device-for-media-stream":
options.add_argument("--use-fake-device-for-media-stream")
options.add_argument("--use-file-for-fake-video-capture=C:\Testfiles\videofiles\bus_cif.y4m")
Both Options are working totally fine used in a batch-file with chrome.exe. For example, the following batch is working fine and used fake webcam videofile:
"C:\Program Files\Google\Chrome\Application\chrome.exe" --use-fake-device-for-media-stream --use-file-for-fake-video-capture=C:\Testfiles\videofiles\bus_cif.y4
Also, the rest of my python chrome webdriver script options are working fine, so the code itself should be correct. For example, the following options are working fine:
options.add_argument("--allow-file-access-from-files")
options.add_argument("--use-fake-ui-for-media-stream")
options.add_argument("--disable-infobars")
Chrome 97.x (with newest stable chromium webdriver files)
Is there something special about the option "use-file-for-fake-video-capture" when used in a python script with options? Or perhaps the path have to be in another format?
Thanks a lot!
Upvotes: 1
Views: 4054
Reputation: 41
Figured it out. Spent hours yesterday, but today shortly after posting to stackoverflow, I found the solution myself:
Problem is the path I used: Windows path in Python
When using the following, everything works fine and fake video is used even when chrome is started by python script:
options = Options()
options.add_argument("--use-fake-ui-for-media-stream")
options.add_argument("--use-fake-device-for-media-stream")
options.add_argument(r'--use-file-for-fake-video-capture=C:\Testfiles\videofiles\bus_cif.y4m')
self.driver = webdriver.Chrome(options=options)
Important is the r' when using windows path with backslashes. I think the other solution would be using slash instead of backslash.
Upvotes: 3