Tips for bypassing camera and microphone pop-up notifications in Selenium WebDriver tests

At the moment, my tests follow a specific flow that triggers microphone and camera alert popups in Chrome:

https://i.stack.imgur.com/QHwF5.jpg

I am looking for a solution to disable these alerts using Selenium Webdriver with Java. I have already tried using Chrome options, but without success. Here is an example of the code I used:

ChromeOptions op = new ChromeOptions();
Map<String, Object> prefs = new HashMap<>();
prefs.put("profile.default_content_setting_values.media_stream_mic", 1);
prefs.put("profile.default_content_setting_values.media_stream_camera", 1);
prefs.put("profile.default_content_setting_values.geolocation", 1);
prefs.put("profile.default_content_setting_values.notifications", 1);
op.setExperimentalOption("prefs", prefs);
RemoteWebDriver remoteDriver = new RemoteWebDriver(new URL(REMOTE_HUB_URL), op);

I've also attempted the following code snippet on its own with no success:

prefs.put("profile.default_content_settings.popups", 1);

Answer №1

Make sure to set the value to "2" when implementing that feature in your code. Snippet:

...
prefs.put("profile.default_content_setting_values.media_stream_mic", 2);
prefs.put("profile.default_content_setting_values.media_stream_camera", 2);
...

Note: Use "1" to allow the option and "2" to block it.

I trust this information proves helpful for you!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Inconsistencies in timing when using WebDriverWait and clicking with Selenium

I have a collection of div elements that are used to toggle the visibility of content in an accordion style. Here is the HTML structure: <div class="accordionContainer"> <div class="accordion"> <h3>Click This</h3> ...

Bypass the entire test suite in the event of a failed assertion in any individual test

JUnit.xml :: <suite name="Suite" maintain-order="true" parallel="false" verbose="1"> <test name="TestCases" maintain-order="true"> <classes> <class name="functionalTests.FunctionalTestCase01"> ...

While using Appium/Protractor for testing a Cordova app, I encountered an issue when running a simple test. The test failed with an error message stating: "Failed to get sockets matching: @web

I'm facing an issue while trying to perform a simple test on my hybrid app using Appium + Protractor. The error message I am encountering is: Failed to get sockets matching: @webview_devtools_remote_.*15239 I have Ubuntu installed and have set up App ...

Configuring the port for the live server while executing tests in Django

I am currently developing a web application using Django and deploying it with Docker. I want to conduct testing on the container using Selenium, specifically through Selenium Grid. However, I have encountered an issue where I need to port forward a specif ...

In Python, selenium repeatedly captures screenshots of the same first element within the loop

Trying to capture individual screenshots of every comment within a Reddit post using Selenium in Python has been quite the challenge. All comments share the same id/class which I have used for selection. Below is the snippet of code that I am currently wo ...

Tips for creating a Random Date of Birth using Selenium

Here is my HTML code snippet: < input name="txtDDOB" tabIndex="7" id="txtDDOB" style="top: -2px; width: 128px; position: relative;" onblur="checkForDate()" type="text" range="1850-2050" format="%m/%d/%Y" value="01/01/1900"/> I am looking to generate a ...

What are the variances in using xpath with selenium webdriver?

WebElement element4=driver.findElement(By.xpath("/html/body/div/table/tbody/tr[2]/td[2]/div/div/div/div[4]/ul/li[3]/a")); WebElement element3=driver.findElement(By.xpath("//*[@id='nav_cat_3']")); When retrieving xpaths using firebug, both xpath ...

Finding the element '54' using protractor, without relying on xpath

Having trouble finding the number 54 (or the entire internal div) in this HTML snippet. I prefer not to use xpath since my page structure changes based on search results. Is there a way to locate it using CSS, maybe? PS: I'm testing an Angular applic ...

In Java with Selenium, I used the command list.clear() to empty the list that was previously storing the result I was trying to keep in a

As I attempted to store country and state values in a map with key-value pairs while looping through each country to obtain the list of states, I encountered an issue. Every time I selected a new country, I tried to clear the existing list using list.cle ...

Appium successfully triggers a click action on an obscured WebElement

I am facing an issue with my android appium test for an android application. The app contains a webview with a loader that appears at the start. There is a link within the app that I need to click on, which should navigate to another web-page. Although ...

Tips for utilizing one catch block to handle both TestNG assertion errors and RunTime exceptions

In my TestNG framework with Java and Selenium, I have created two custom methods to handle WebElement interactions. Here they are: // Checks if a WebElement is present on the screen public boolean isElementPresent(WebElement element) { try { e ...

generate code to automatically output the content of a website

I'm in the process of creating a program that automatically navigates to a website and prints a page. Unfortunately, I'm encountering difficulties in getting it to function properly. I've attempted using the selenium chrome driver, but with ...

Is there a way to instruct Selenium to pause until the next page is fully loaded, with identical URL and fields replicated?

I am trying to perform a product search using the following code: driver.findElement(By.id("submit")).sendKeys(Keys.ENTER); driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS); driver.findElement(By.id("search-trigger")).sendKeys(Keys.ENTER); ...

"Executing the jar file results in 'JAX-RS MessageBodyWriter not found for media type=application/json' error, however running mvn:exec works perfectly

I am facing a challenge while trying to package my maven project. Initially, I developed and tested it using mvn:exec and everything worked perfectly fine. However, after generating the jar file with dependencies using mvn package, I encountered an issue. ...

Creating dynamic JSON endpoints using JSP with Spring MVC

When working with JSON in my webapp, I have successfully passed a variable wordId to the Spring-mvc Controller using a static URL. However, I am unsure of the best practice for dealing with dynamic or parametric URLs. Controller Section: @RequestMapping( ...

Attempting to reveal the gridview that has been hidden due to a server-side command

I am attempting to make the gridview visible that is hidden by the server side on page load method in C#. protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.BindDummyRow(); } ...

Scraping the web with a webdriver using a for loop

My task involves scraping data from this specific website: this link. The main challenge is to extract content located in the right box of each page until the last item is reached. This means that clicking on the "<이전글" (previous item) or "다음 ...

Error encountered while invoking the constructor

Looking for some assistance with my java class that implements the page object pattern. Here's what I have: package core.pageObjects; import org.openqa.selenium.*; public class ConsultaClientePorDocumento { private WebDriver driver; publi ...

Are you getting an empty set with your Selenium XPATH query?

I recently checked out this website: After waiting for the page to load, I wrote the following python code: try: tmp = driver.find_elements(By.XPATH, '//*[text()="Login"]') print(tmp) except Exception as e: print('NONE ...

Facing difficulties in initiating Selenium with PhantomJS/GhostDriver as child processes

I am currently working on a Node script that involves using the child_process module in order to run a Selenium server with PhantomJS's GhostDriver. I have imported the module: Child = require "child_process" This is how I am attempting to start the ...