How to enable media device access in Edge browser using Selenium?

2024/11/16 10:22:23

I have a Selenium test I want to run in Edge against a page which uses the webcam and microphone. In order for those media devices to work in the browser, the user has to allow the site access to the device.

This is a quick example fiddle I made which illustrates that behaviour in Edge: https://jsfiddle.net/12t3nofL/

You should notice the popup bar at the bottom of the screen, I need this to be automatically allowed in my automation.

I found these existing Q/As on SO already which suggest there is a way to allow media devices via the webdriver options, but they just don't work for me:

how to allow mic/camera in edge web browse suing selenium

How to enable 'Mircophone' access in Edge browser using Selenium?

This is my code (you may need to pip install selenium==3.141.0 first):

from selenium import webdriver
from selenium.webdriver.edge.options import Options
options = Options()
options.set_capability("dom.webnotifications.enabled", 1)
options.set_capability("permissions.default.microphone", 1)
options.set_capability("permissions.default.camera", 1)
capabilities = options.to_capabilities()
driver = webdriver.Edge(capabilities=capabilities)
driver.get('https://jsfiddle.net/12t3nofL')

And the permissions bar still pops up at the bottom every time.

I am on Selenium 3.141.0 and Python 3.7.0 (though have the same issue in 2.7).

Note: due to other reasons, I have Edge set to clear sessions on exit so cookies and cache are not preserved - in an attempt to mimic the fresh profile you get with automated Chrome.

Answer

I have reproduced the problem on my machine, but I think this is a Windows behavior, and we can't set using selenium.

From this article, we can see that:

How to allow a website to use your camera or microphone while browsing in Microsoft Edge

You can use your camera and microphone for websites in Microsoft Edge. However, even when your camera and microphone are enabled for Microsoft Edge, you will still need to give individual websites permission before they can use your camera and microphone. Here’s how:

  1. Go to a website that wants to use your microphone and/or camera.
  2. If a dialog box appears asking if you want to give the website permission to use your camera or microphone, select Allow once or Always allow, or close the dialog box to block access.

After allowed the permission, we can find this permission under the Manage permissions (Edge browser setting => Advanced => Manage permissions), screenshot as below:

enter image description here

From your description, when Edge browser exit, you will clear sessions, cookie and cache, if you don't want to allow, the permission every time, you could uncheck the Website Permissions option (screenshot as below), the permission prompts will only show when we first visit the page.

enter image description here

https://en.xdnf.cn/q/119203.html

Related Q&A

Print specific rows that are common between two dataframes

i have a dataframe (df1) like this id link 1 google.com 2 yahoo.com 3 gmail.comi have another dataframe(df2) like this: id link numberOfemployees 1 linkedin.com …

What is the problem with buttons connection in PyQt5?

I have the problem that I cannot connect the implementation between two buttons. After I pressed the "Grayscale" button and got the grayscale image, I pressed the "Canny" button but…

Install ipykernel in vscode - ipynb (Jupyter)

Greetings! I am not able to install ipykernel and receiving following error. Please advise. print(Hello) Running cells with Python 3.10.5 64-bit requires ipykernel package. Run the following command to…

How do I write a form in django

I am writing a forums app for my final project in class and I am trying to write a form for creating a new thread, Basically all I need it to do is username: text box hereName of thread: Text box here…

Whats the difference between namespaces and names?

Im assuming the namespace is the allotted place in memory in which the name is to be stored. Or are they the same thing?

Finding a string in python and writing it in another file [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.Want to improve this question? Add details and clarify the problem by editing this post.Closed 10 years ago.Improv…

Python error TypeError: function takes exactly 1 argument (5 given)

Traceback (most recent call last):File "wdd.py", line 164, in <module>file.write("temperature is ", temperature, "wet is ", humidity, "%\n") TypeError: fun…

Django session not available on two seperate requests

Description: In the django session docs it says:You can read it and write to request.session at any point in your view.But I cant access the session when making a second request to the same view: views…

Counting how many times there are blank lists in a list of list [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.This question was caused by a typo or a problem that can no longer be reproduced. While similar q…

Generating a list of random permutations of another list

So, Im trying to tackle the TSP with a Genetic Algorithm. To do that I need to create a population pool. What I want to accomplish is to create a list of random permutations that will represent a popul…