Handle Permission Pop-ups

This article shows you how to handle user permission pop-ups, alerts, and prompts in your automated tests on BrowserStack.

Introduction

Some functionalities in your web apps may need user-permissions. For instance:

  • access to device location
  • access camera and/or microphone
  • permission to show notifications
  • access to device storage, etc.

The browser then triggers a pop-up box with ‘Confirm’ or ‘Deny’ interactions. In this page, you’ll see how to automate those interactions on remote browsers and real mobile devices.

Common permission pop-ups (on desktop and mobile):

This section contains the common permission pop-ups and how you can automate them on Desktop and Real Mobile Devices.

1. “Know your location” pop-up

You can test what happens when your web app is allowed to (or blocked from) accessing the device location, using Automate.

access device locationaccess device location2

Desktop:

The snippet below lets you automate an ‘Allow’ or ‘Block’ interaction when the remote Chrome browser asks for location.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class AllowGeoLocationPopup {
  public static final String AUTOMATE_USERNAME = "YOUR_USERNAME";
  public static final String AUTOMATE_KEY = "YOUR_ACCESS_KEY";
  public static final String URL = "https://" + AUTOMATE_USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";

  public static void main(String[] args) throws Exception {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("browser", "Chrome");
    caps.setCapability("browser_version", "75.0");
    caps.setCapability("os", "Windows");
    caps.setCapability("os_version", "10");

    // INIT CHROME OPTIONS
    ChromeOptions options = new ChromeOptions();
    Map < String, Object > prefs = new HashMap < String, Object > ();
    Map < String, Object > profile = new HashMap < String, Object > ();
    Map < String, Object > contentSettings = new HashMap < String, Object > ();

    // SET CHROME OPTIONS
    // 0 - Default, 1 - Allow, 2 - Block
    contentSettings.put("geolocation", 1);
    profile.put("managed_default_content_settings", contentSettings);
    prefs.put("profile", profile);
    options.setExperimentalOption("prefs", prefs);

    // SET CAPABILITY
    caps.setCapability(ChromeOptions.CAPABILITY, options);
    WebDriver driver = new RemoteWebDriver(new URL(URL), caps);
    driver.get("https://the-internet.herokuapp.com/geolocation");
    driver.findElement(By.xpath("//*[@id='content']/div/button")).click();
    Thread.sleep(5000);
    driver.quit();
  }
}
var chrome = require("selenium-webdriver/chrome");

// SET CAPABILITY
var capabilities = {
  'browserName' : 'Chrome',
  'browser_version' : '75.0',
  'os' : 'Windows',
  'os_version' : '10',
  'browserstack.user' : 'YOUR_USERNAME',
  'browserstack.key' : 'YOUR_ACCESS_KEY',

  // SET CHROME OPTIONS
  'goog:chromeOptions': {
    prefs: {
      // 0 - Default, 1 - Allow, 2 - Block
      'profile.managed_default_content_settings.geolocation' : 1
    }
  }
}

var driver = new webdriver.Builder()
  .usingServer('http://hub-cloud.browserstack.com/wd/hub/')
  .withCapabilities(capabilities)
  .build();

driver.get('https://the-internet.herokuapp.com/geolocation')
  .then(function(){
    driver.findElement(webdriver.By.xpath("//*[@id='content']/div/button")).click()
      .then(function(){
        driver.quit();
      });
  });
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System.Threading;
using System.Collections.Generic;
namespace SampleCSharp {
  public class AllowGeoLocationPopup {
    static void Main(string[] args) {
      IWebDriver driver;
      Dictionary<string, object> profile = new Dictionary<string, object>();

      // 0 - Default, 1 - Allow, 2 - Block
      profile.Add("profile.default_content_setting_values.geolocation", 1);

      // INIT CHROME OPTIONS
      Dictionary<string, object> chromeOptions = new Dictionary<string, object>();

      // SET CHROME OPTIONS
      chromeOptions.Add("prefs", profile);

      // SET CAPABILITY
      DesiredCapabilities capability = new DesiredCapabilities();
      capability.SetCapability("browser", "Chrome");
      capability.SetCapability("browser_version", "75.0");
      capability.SetCapability("os", "Windows");
      capability.SetCapability("os_version", "10");
      capability.SetCapability("browserstack.debug", "true");
      capability.SetCapability("browserstack.user", "YOUR_USERNAME");
      capability.SetCapability("browserstack.key", "YOUR_ACCESS_KEY");
      capability.SetCapability("chromeOptions", chromeOptions);

      driver = new RemoteWebDriver(new Uri("http://hub-cloud.browserstack.com/wd/hub/"), capability);
      driver.Navigate().GoToUrl("https://the-internet.herokuapp.com/geolocation");
      driver.FindElement(By.XPath("//*[@id='content']/div/button")).Click();
      Thread.Sleep(5000);
      driver.Quit();
    }
  }
}
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options

# INIT CHROME OPTIONS
chrome_options = Options()
# 0 - Default, 1 - Allow, 2 - Block

# SET CHROME OPTIONS
chrome_options.add_experimental_option("prefs", { "profile.default_content_setting_values.geolocation": 1})

# SET CAPABILITY
desired_cap = chrome_options.to_capabilities()
desired_cap.update({
  'browser_version': '75.0',
  'os': 'Windows',
  'os_version': '10'
})

driver = webdriver.Remote(command_executor='http://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub', desired_capabilities=desired_cap)
driver.get("https://the-internet.herokuapp.com/geolocation")
driver.find_element_by_xpath("//*[@id='content']/div/button").click()
driver.quit()
require 'rubygems'
require 'selenium-webdriver'

# SET CHROME OPTIONS
# 0 - Default, 1 - Allow, 2 - Block
caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"prefs" => { "profile.default_content_setting_values.geolocation" => 1 } })

# SET CAPABILITY
caps['browser'] = 'Chrome'
caps['browser_version'] = '75.0'
caps['os'] = 'Windows'
caps['os_version'] = '10'
driver = Selenium::WebDriver.for(:remote,
  :url => "http://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub",
  :desired_capabilities => caps)
driver.navigate.to "https://the-internet.herokuapp.com/geolocation"
driver.find_element(:xpath, "//*[@id='content']/div/button").click;
driver.quit

Mobile:

The snippet below lets you automate an ‘Allow’ or ‘Block’ interaction when the remote Chrome browser asks an Android device for location.

import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;

import java.net.URL;
import java.util.Set;

public class AllowGeoLocationPopup {
  public static final String AUTOMATE_USERNAME = "YOUR_USERNAME";
  public static final String AUTOMATE_KEY = "YOUR_ACCESS_KEY";
  public static final String URL = "https://" + AUTOMATE_USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";

  public static void main(String[] args) throws Exception {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("browser", "Chrome");
    caps.setCapability("browserName", "android");
    caps.setCapability("device", "Samsung Galaxy S10");
    caps.setCapability("realMobile", "true");
    caps.setCapability("os_version", "9.0");
    AppiumDriver driver = new AndroidDriver(new URL(URL), caps);
    driver.get("https://the-internet.herokuapp.com/geolocation");
    driver.findElement(By.xpath("//*[@id='content']/div/button")).click();
    Thread.sleep(5000);
    // To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
    driver.context("NATIVE_APP");
    driver.findElement(By.xpath(".//android.widget.Button[@text='Allow']")).click();
    Thread.sleep(5000);
    driver.quit();
  }
}
let webdriver = require('wd');

let capabilities = {
  'os_version': '9.0',
  'device': 'Samsung Galaxy S10',
  'real_mobile': 'true',
  'browserstack.user': 'YOUR_USERNAME',
  'browserstack.key': 'YOUR_ACCESS_KEY',
}

let driver = webdriver.promiseRemote("http://hub-cloud.browserstack.com/wd/hub");
driver.init(capabilities, function() {
  driver.get('https://the-internet.herokuapp.com/geolocation')
    .then(function() {
      (async () => {
        let element = await driver.element("xpath", "//*[@id='content']/div/button");
        await element.click();

        // To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
        await driver.context('NATIVE_APP');
        let element2 = await driver.element("xpath", ".//android.widget.Button[@text='Allow']")
        await element2.click();
        await driver.quit();
      })();
    });
});
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System.Threading;
using System.Collections.Generic;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
using OpenQA.Selenium.Chrome;
namespace SampleCSharp {
  class AllowGeoLocationPopup {
    static void Main(string[] args) {
      DesiredCapabilities capability = new DesiredCapabilities();
      capability.SetCapability("device", "Samsung Galaxy S10");
      capability.SetCapability("real_mobile", "true");
      capability.SetCapability("browserstack.debug", "true");
      capability.SetCapability("browserstack.user", "YOUR_USERNAME");
      capability.SetCapability("browserstack.key", "YOUR_ACCESS_KEY");
      AndroidDriver<IWebElement> driver = new AndroidDriver<IWebElement>(new Uri("http://hub-cloud.browserstack.com/wd/hub"), capability);
      driver.Navigate().GoToUrl("https://the-internet.herokuapp.com/geolocation");
      Thread.Sleep(5000);
      IWebElement ll = driver.FindElement(By.XPath("//*[@id='content']/div/button"));
      ll.Click();
      Thread.Sleep(5000);
      // To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
      driver.Context = ("NATIVE_APP");
      ll =  driver.FindElement(By.XPath(".//android.widget.Button[@text='Allow']"));
      ll.Click();
      driver.Quit();
    }
  }
}
import time
from appium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

desired_cap = {
  'device': 'Samsung Galaxy S10',
  'realMobile': 'true',
  'os_version': '9.0'
}
driver = webdriver.Remote(command_executor='http://YOUR_USERNAME:YOUR_ACCESS_KEY@hub.browserstack.com/wd/hub', desired_capabilities=desired_cap)
driver.get("https://the-internet.herokuapp.com/geolocation")
driver.find_element_by_xpath("//*[@id='content']/div/button").click()
time.sleep(2)
# To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
driver.switch_to.context('NATIVE_APP')
driver.find_element_by_xpath(".//android.widget.Button[@text='Allow']").click()
time.sleep(2)
driver.quit()
require 'rubygems'
require 'appium_lib'

caps = {}
caps['device'] = 'Samsung Galaxy S10'
caps['realMobile'] = 'true'
caps['os_version'] = '9.0'
appium_driver = Appium::Driver.new({
  'caps' => caps,
  'appium_lib' => {
      :server_url => "http://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub"
  }}, true)
driver = appium_driver.start_driver
driver.navigate.to "https://the-internet.herokuapp.com/geolocation"
driver.find_element(:xpath, "//*[@id='content']/div/button").click;
sleep(2)
# To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
driver.set_context('NATIVE_APP')
driver.find_element(:xpath, ".//android.widget.Button[@text='Allow']").click;
sleep(2)
driver.quit

2. “Use your camera” and “Use your microphone” pop-up

You can test what happens when your web app is allowed to (or blocked from) accessing camera or microphone, using Automate.

use camera android use_microphone_android use_camera_android2 use_microphone_android2

Desktop:

The snippet below lets you automate an ‘Allow’ or ‘Block’ interaction when your web app requests access to camera or microphone.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.net.URL;

public class AllowCameraPopupChrome {
  public static final String AUTOMATE_USERNAME = "YOUR_USERNAME";
  public static final String AUTOMATE_KEY = "YOUR_ACCESS_KEY";
  public static final String URL = "https://" + AUTOMATE_USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";

  public static void main(String[] args) throws Exception {

    //Configure ChromeOptions to pass fake media stream
    ChromeOptions options = new ChromeOptions();
    options.addArguments("use-fake-device-for-media-stream");
    options.addArguments("use-fake-ui-for-media-stream");

    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("browser", "Chrome");
    caps.setCapability("browser_version", "75.0");
    caps.setCapability("os", "Windows");
    caps.setCapability("os_version", "10");
    caps.setCapability(ChromeOptions.CAPABILITY, options);
    WebDriver driver = new RemoteWebDriver(new URL(URL), caps);

    //WebCam Test
    driver.get("https://webcamtests.com/check");
    Thread.sleep(5000);
    driver.findElement(By.id("webcam-launcher")).click();
    Thread.sleep(2000);

    //Mic Test
    driver.get("https://www.vidyard.com/mic-test/");
    Thread.sleep(2000);
    driver.findElement(By.xpath("(//*[@class='button' and text()='Grant access'])[1]")).click();
    Thread.sleep(2000);

    driver.quit();
  }
}
var webdriver = require('selenium-webdriver');
var chrome = require("selenium-webdriver/chrome");

var capabilities = {
  'browserName': 'Chrome',
  'browser_version': '75.0',
  'os': 'Windows',
  'os_version': '10',
  'browserstack.user': 'YOUR_USERNAME',
  'browserstack.key': 'YOUR_ACCESS_KEY',

  // Configure ChromeOptions to pass fake media stream
  'goog:chromeOptions': {
    'args': ["--use-fake-device-for-media-stream", "--use-fake-ui-for-media-stream"]
  }
}

var driver = new webdriver.Builder()
  .usingServer('http://hub-usw.browserstack.com/wd/hub')
  .withCapabilities(capabilities)
  .build();

// Webcam Test
driver.get('https://webcamtests.com/check')
  .then(function() {
    setTimeout(function() {
      driver.findElement(webdriver.By.id("webcam-launcher")).click()
        .then(function() {
          setTimeout(function() {
            // Mic Test
            driver.get('https://www.vidyard.com/mic-test/')
              .then(function() {
                driver.findElement(webdriver.By.xpath("//*[@class='button' and text()='Grant access'][1]")).click()
                  .then(function() {
                    setTimeout(function() {
                        driver.quit();
                    }, 2000);
                });
              });
          }, 2000);
        });
    }, 2000);
  });
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System.Threading;
using OpenQA.Selenium.Chrome;

namespace SampleCSharp {
  public class AllowCameraMicPopupChrome {
    static void Main(string[] args) {
      IWebDriver driver;

      //Configure ChromeOptions to pass fake media stream
      ChromeOptions chromeOptions = new ChromeOptions();
      chromeOptions.AddArgument("--use-fake-device-for-media-stream");
      chromeOptions.AddArgument("--use-fake-ui-for-media-stream");

      DesiredCapabilities capability = (DesiredCapabilities)chromeOptions.ToCapabilities();
      capability.SetCapability("browser", "Chrome");
      capability.SetCapability("browser_version", "70.0");
      capability.SetCapability("os", "Windows");
      capability.SetCapability("os_version", "10");
      capability.SetCapability("browserstack.user", "YOUR_USERNAME");
      capability.SetCapability("browserstack.key", "YOUR_ACCESS_KEY");
      driver = new RemoteWebDriver(
        new Uri("http://kaustubhmahajan2:wzXHk99HRwSwKU9qaQ74@hub-cloud.browserstack.com/wd/hub/"), capability);

      // Webcam Test           
      driver.Navigate().GoToUrl("https://webcamtests.com/check");
      Thread.Sleep(2000);
      driver.FindElement(By.Id("webcam-launcher")).Click();
      Thread.Sleep(2000);

      // Mic Test
      driver.Navigate().GoToUrl("https://www.vidyard.com/mic-test/");
      Thread.Sleep(2000);
      driver.FindElement(By.XPath("//*[@class='button' and text()='Grant access'][1]")).Click();
      Thread.Sleep(2000);

      driver.Quit();
    }
  }
}
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
import time

desired_cap = {
  'browser_version': '75.0',
  'os': 'Windows',
  'os_version': '10',

  #Configure ChromeOptions to pass fake media stream
  'chromeOptions': {
    'args': ["--use-fake-device-for-media-stream", "--use-fake-ui-for-media-stream"]
  }
}
driver = webdriver.Remote(command_executor = 'http://YOUR_USERNAME:YOUR_ACCESS_KEY@hub.browserstack.com/wd/hub', desired_capabilities = desired_cap)

# WebCam Test
driver.get("https://webcamtests.com/check")
time.sleep(5)
driver.find_element_by_id("webcam-launcher").click()
time.sleep(2)

# Mic Test
driver.get("https://www.vidyard.com/mic-test/")
time.sleep(5)
driver.find_element_by_xpath("//*[@class='button' and text()='Grant access'][1]").click()
time.sleep(2)
driver.quit()
require 'rubygems'
require 'selenium-webdriver'

#Configure ChromeOptions to pass fake media stream
caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"args" => ['--use-fake-device-for-media-stream', '--use-fake-ui-for-media-stream'] })
caps['browser'] = 'Chrome'
caps['browser_version'] = '75.0'
caps['os'] = 'Windows'
caps['os_version'] = '10'
driver = Selenium::WebDriver.for(:remote, :url => "http://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub", :desired_capabilities => caps)

# WebCam Test
driver.navigate.to "https://webcamtests.com/check"
sleep(5)
driver.find_element(:id, "webcam-launcher").click;
sleep(2)

#Mic Test
driver.navigate.to "https://www.vidyard.com/mic-test/"
sleep(5)
driver.find_element(:xpath, "//*[@class='button' and text()='Grant access'][1]").click;
sleep(2)

driver.quit

Mobile:

The snippet below lets you automate an ‘Allow’ or ‘Block’ interaction on Android devices when the remote Chrome browser asks for access to camera or microphone.

import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;

import java.net.URL;

public class AllowCameraPopupChromeMobile {
  public static final String AUTOMATE_USERNAME = "YOUR_USERNAME";
  public static final String AUTOMATE_KEY = "YOUR_ACCESS_KEY";
  public static final String URL = "https://" + AUTOMATE_USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";

  public static void main(String[] args) throws Exception {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("browser", "Chrome");
    caps.setCapability("device", "Samsung Galaxy S10");
    caps.setCapability("realMobile", "true");
    caps.setCapability("os_version", "9.0");
    AppiumDriver driver = new AndroidDriver(new URL(URL), caps);

    //WebCam Test
    driver.get("https://webcamtests.com/check");
    Thread.sleep(2000);
    driver.findElement(By.id("webcam-launcher")).click();
    Thread.sleep(2000);
    // To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
    driver.context("NATIVE_APP");
    driver.findElement(By.xpath(".//android.widget.Button[@text='Allow']")).click();
    driver.findElement(By.xpath(".//android.widget.Button[@text='Allow']")).click();
    Thread.sleep(2000);

    driver.context("CHROMIUM");

    //Mic Test
    driver.get("https://webcammictest.com/check-microphone.html");
    Thread.sleep(2000);
    driver.findElement(By.xpath("//button[contains(@class, 'button') and text()='Check my microphone']")).click();
    Thread.sleep(2000);
    driver.context("NATIVE_APP");
    driver.findElement(By.xpath(".//android.widget.Button[@text='Allow']")).click();
    driver.findElement(By.xpath(".//android.widget.Button[@text='Allow']")).click();
    Thread.sleep(2000);

    driver.quit();
  }
}
let webdriver = require('wd');

let capabilities = {
  'os_version': '9.0',
  'device': 'Samsung Galaxy S10',
  'real_mobile': 'true',
  'browserstack.user': 'YOUR_USERNAME',
  'browserstack.key': 'YOUR_ACCESS_KEY'
}

const sleep = require('util').promisify(setTimeout)
let driver = webdriver.promiseRemote("http://hub-cloud.browserstack.com/wd/hub");
driver.init(capabilities, function() {
  (async () => {
    // Camera Test
    await driver.get('https://webcamtests.com/check');
    await sleep(3000);
    let element = await driver.element("id", "webcam-launcher");
    await element.click();

    // To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
    await driver.context('NATIVE_APP');
    let element2 = await driver.element("xpath", ".//android.widget.Button[@text='Allow']")
    await element2.click();
    let element3 = await driver.element("xpath", ".//android.widget.Button[@text='Allow']")
    await element3.click();
    await sleep(3000);

    await driver.context('CHROMIUM');

    // Mic Test
    await driver.get('https://webcammictest.com/check-microphone.html');
    await sleep(3000);
    let element4 = await driver.element("xpath", "//button[contains(@class, 'button') and text()='Check my microphone']");
    await element4.click();
    await driver.context('NATIVE_APP');
    let element5 = await driver.element("xpath", ".//android.widget.Button[@text='Allow']")
    await element5.click();
    let element6 = await driver.element("xpath", ".//android.widget.Button[@text='Allow']")
    await element6.click();
    await sleep(3000);
    await driver.quit();
  })();
});
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System.Threading;
using OpenQA.Selenium.Appium.Android;

namespace SampleCSharp {
  class Program {
    static void Main(string[] args) {
      DesiredCapabilities capability = new DesiredCapabilities();
      capability.SetCapability("device", "Samsung Galaxy S10");
      capability.SetCapability("real_mobile", "true");
      capability.SetCapability("browserstack.user", "YOUR_USERNAME");
      capability.SetCapability("browserstack.key", "YOUR_ACCESS_KEY");

      AndroidDriver<IWebElement> driver = new AndroidDriver<IWebElement>(new Uri("http://hub-cloud.browserstack.com/wd/hub"), capability);

      // Camera Test
      driver.Navigate().GoToUrl("https://webcamtests.com/check");
      Thread.Sleep(2000);
      IWebElement ll = driver.FindElement(By.Id("webcam-launcher"));
      ll.Click();
      // To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
      driver.Context = ("NATIVE_APP");
      ll =  driver.FindElement(By.XPath(".//android.widget.Button[@text='Allow']"));
      ll.Click();
      ll =  driver.FindElement(By.XPath(".//android.widget.Button[@text='Allow']"));
      ll.Click();
      Thread.Sleep(2000);

      driver.Context = ("CHROMIUM");

      // Mic Test
      driver.Navigate().GoToUrl("https://webcammictest.com/check-microphone.html");
      Thread.Sleep(2000);
      ll = driver.FindElement(By.XPath("//button[contains(@class, 'button') and text()='Check my microphone']"));
      ll.Click();
      driver.Context = ("NATIVE_APP");
      ll =  driver.FindElement(By.XPath(".//android.widget.Button[@text='Allow']"));
      ll.Click();
      ll =  driver.FindElement(By.XPath(".//android.widget.Button[@text='Allow']"));
      ll.Click();
      Thread.Sleep(2000);
      driver.Quit();
    }
  }
}
import time
from appium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

desired_cap = {
  'device': 'Samsung Galaxy S10',
  'realMobile': 'true',
  'os_version': '9.0'
}
driver = webdriver.Remote(command_executor='http://YOUR_USERNAME:YOUR_ACCESS_KEY@hub.browserstack.com/wd/hub', desired_capabilities=desired_cap)

# Camera Test
driver.get("https://webcamtests.com/check")
time.sleep(2)
driver.find_element_by_id("webcam-launcher").click()
# To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
driver.switch_to.context('NATIVE_APP')
driver.find_element_by_xpath(".//android.widget.Button[@text='Allow']").click()
driver.find_element_by_xpath(".//android.widget.Button[@text='Allow']").click()
time.sleep(2)

driver.switch_to.context('CHROMIUM')

# Mic Test
driver.get("https://webcammictest.com/check-microphone.html")
time.sleep(2)
driver.find_element_by_xpath("//button[contains(@class, 'button') and text()='Check my microphone']").click()
driver.switch_to.context('NATIVE_APP')
driver.find_element_by_xpath(".//android.widget.Button[@text='Allow']").click()
driver.find_element_by_xpath(".//android.widget.Button[@text='Allow']").click()
time.sleep(2)
driver.quit()
require 'rubygems'
require 'appium_lib'

caps = {}
caps['device'] = 'Samsung Galaxy S10'
caps['realMobile'] = 'true'
caps['os_version'] = '9.0'
appium_driver = Appium::Driver.new({'caps' => caps,'appium_lib' => { :server_url => "http://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub" }}, true)
driver = appium_driver.start_driver

# WebCam Test
driver.navigate.to "https://webcamtests.com/check"
sleep(2)
driver.find_element(:id, "webcam-launcher").click;
# To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
driver.set_context('NATIVE_APP')
driver.find_element(:xpath, ".//android.widget.Button[@text='Allow']").click;
driver.find_element(:xpath, ".//android.widget.Button[@text='Allow']").click;
sleep(2)

driver.set_context('CHROMIUM')

# Mic Test
driver.navigate.to "https://webcammictest.com/check-microphone.html"
sleep(2)
driver.find_element(:xpath, "//button[contains(@class, 'button') and text()='Check my microphone']").click;
driver.set_context('NATIVE_APP')
driver.find_element(:xpath, ".//android.widget.Button[@text='Allow']").click;
driver.find_element(:xpath, ".//android.widget.Button[@text='Allow']").click;
sleep(2)
driver.quit

3. “Show notifications” pop-up

show_notification_request show_notification_request2

Desktop:

The snippet below lets you automate an ‘Allow’ or ‘Block’ interaction when your web app requests permission to show notifications.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class AllowNotificationPopupDesktop {
  public static final String AUTOMATE_USERNAME = "YOUR_USERNAME";
  public static final String AUTOMATE_KEY = "YOUR_ACCESS_KEY";
  public static final String URL = "https://" + AUTOMATE_USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";

  public static void main(String[] args) throws Exception {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("browser", "Chrome");
    caps.setCapability("browser_version", "75.0");
    caps.setCapability("os", "Windows");
    caps.setCapability("os_version", "10");

    // INIT CHROME OPTIONS
    ChromeOptions options = new ChromeOptions();
    Map<String, Object> prefs = new HashMap<String, Object>();
    Map<String, Object> profile = new HashMap<String, Object>();
    Map<String, Object> contentSettings = new HashMap<String, Object>();

    // SET CHROME OPTIONS
    // 0 - Default, 1 - Allow, 2 - Block
    contentSettings.put("notifications", 1);
    profile.put("managed_default_content_settings", contentSettings);
    prefs.put("profile", profile);
    options.setExperimentalOption("prefs", prefs);

    // SET CAPABILITY
    caps.setCapability(ChromeOptions.CAPABILITY, options);

    WebDriver driver = new RemoteWebDriver(new URL(URL), caps);

    driver.get("https://web-push-book.gauntface.com/demos/notification-examples/");
    driver.findElement(By.xpath("//*[@class='js-notification-overview' and text() = 'Example Notification']")).click();
    Thread.sleep(2000);
    driver.quit();
  }
}
var webdriver = require('selenium-webdriver');
var chrome = require("selenium-webdriver/chrome");

var capabilities = {
  'browserName': 'Chrome',
  'browser_version': '75.0',
  'os': 'Windows',
  'os_version': '10',
  'browserstack.user': 'YOUR_USERNAME',
  'browserstack.key': 'YOUR_ACCESS_KEY',
  'goog:chromeOptions': {
    prefs: {
      // 0 - Default, 1 - Allow, 2 - Block
      'profile.managed_default_content_settings.notifications': 1
    }
  }
}

var driver = new webdriver.Builder()
  .usingServer('http://hub-usw.browserstack.com/wd/hub')
  .withCapabilities(capabilities)
  .build();

driver.get('https://web-push-book.gauntface.com/demos/notification-examples/')
  .then(function() {
    driver.findElement(webdriver.By.xpath("//*[@class='js-notification-overview' and text() = 'Example Notification']")).click()
      .then(function() {
        driver.quit();
      });
  });
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System.Threading;
using System.Collections.Generic;
namespace SampleCSharp {
  public class AllowNotificationPopup {
    static void Main(string[] args) {
      IWebDriver driver;
      Dictionary<string, object> profile = new Dictionary<string, object>();
      // 0 - Default, 1 - Allow, 2 - Block
      profile.Add("profile.default_content_setting_values.notifications", 1);
      Dictionary<string, object> chromeOptions = new Dictionary<string, object>();
      chromeOptions.Add("prefs", profile);
      DesiredCapabilities capability = new DesiredCapabilities();
      capability.SetCapability("browser", "Chrome");
      capability.SetCapability("browser_version", "75.0");
      capability.SetCapability("os", "Windows");
      capability.SetCapability("os_version", "10");
      capability.SetCapability("browserstack.user", "YOUR_USERNAME");
      capability.SetCapability("browserstack.key", "YOUR_ACCESS_KEY");
      capability.SetCapability("chromeOptions", chromeOptions);
      driver = new RemoteWebDriver(new Uri("http://hub-cloud.browserstack.com/wd/hub/"), capability);
      driver.Navigate().GoToUrl("https://web-push-book.gauntface.com/demos/notification-examples/");
      driver.FindElement(By.XPath("//*[@class='js-notification-overview' and text() = 'Example Notification']")).Click();
      Thread.Sleep(2000);
      driver.Quit();
    }
  }
}
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
import time

# 0 - Default, 1 - Allow, 2 - Block
chrome_options = Options()
chrome_options.add_experimental_option("prefs", { "profile.default_content_setting_values.notifications": 1})
desired_cap = chrome_options.to_capabilities()
desired_cap.update({
  'browser_version': '75.0',
  'os': 'Windows',
  'os_version': '10'
})
driver = webdriver.Remote(command_executor='http://YOUR_USERNAME:YOUR_ACCESS_KEY@hub.browserstack.com/wd/hub', desired_capabilities=desired_cap)
driver.get("https://web-push-book.gauntface.com/demos/notification-examples/")
driver.find_element_by_xpath("//*[@class='js-notification-overview' and text() = 'Example Notification']").click()
time.sleep(2)
driver.quit()
require 'rubygems'
require 'selenium-webdriver'

# 0 - Default, 1 - Allow, 2 - Block
caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"prefs" => { "profile.default_content_setting_values.notifications" => 1 } })
caps['browser'] = 'Chrome'
caps['browser_version'] = '75.0'
caps['os'] = 'Windows'
caps['os_version'] = '10'
driver = Selenium::WebDriver.for(:remote,
  :url => "http://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub",
  :desired_capabilities => caps)
driver.navigate.to "https://web-push-book.gauntface.com/demos/notification-examples/"
driver.find_element(:xpath, "//*[@class='js-notification-overview' and text() = 'Example Notification']").click;
sleep(2)
driver.quit

Mobile:

The snippet below lets you automate an ‘Allow’ or ‘Block’ interaction on Android devices when the remote Chrome browser asks for permission to show notifications.

import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;

import java.net.URL;
import java.util.Set;

public class AllowNotificationPopupMobile {
  public static final String AUTOMATE_USERNAME = "YOUR_USERNAME";
  public static final String AUTOMATE_KEY = "YOUR_ACCESS_KEY";
  public static final String URL = "https://" + AUTOMATE_USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";

  public static void main(String[] args) throws Exception {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("browser", "Chrome");
    caps.setCapability("browserName", "android");
    caps.setCapability("device", "Samsung Galaxy S10");
    caps.setCapability("realMobile", "true");
    caps.setCapability("os_version", "9.0");
    AppiumDriver driver = new AndroidDriver(new URL(URL), caps);

    driver.get("https://web-push-book.gauntface.com/demos/notification-examples/");
    driver.findElement(By.xpath("//*[@class='js-notification-overview' and text() = 'Example Notification']")).click();
    Thread.sleep(2000);

    Set contextHandles = driver.getContextHandles();
    // To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
    driver.context("NATIVE_APP");
    driver.findElement(By.xpath(".//android.widget.Button[@text='Allow']")).click();
    Thread.sleep(2000);
    driver.quit();
  }
}
let webdriver = require('wd');

let capabilities = {
    'os_version': '9.0',
    'device': 'Samsung Galaxy S10',
    'real_mobile': 'true',
    'browserstack.user': 'YOUR_USERNAME',
    'browserstack.key': 'YOUR_ACCESS_KEY'
}

let driver = webdriver.promiseRemote("http://hub-cloud.browserstack.com/wd/hub");
driver.init(capabilities, function() {
  driver.get('https://web-push-book.gauntface.com/demos/notification-examples/')
    .then(function() {
      (async () => {
        let element = await driver.element("xpath", "//*[@class='js-notification-overview' and text() = 'Example Notification']");
        await element.click();

        // To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
        await driver.context('NATIVE_APP');
        let element2 = await driver.element("xpath", ".//android.widget.Button[@text='Allow']")
        await element2.click();
        await driver.quit();
      })();
    });
});
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System.Threading;
using OpenQA.Selenium.Appium.Android;
namespace SampleCSharp {
  class AllowNotificationPopup {
    static void Main(string[] args) {
      DesiredCapabilities capability = new DesiredCapabilities();
      capability.SetCapability("device", "Samsung Galaxy S10");
      capability.SetCapability("real_mobile", "true");
      capability.SetCapability("browserstack.user", "YOUR_USERNAME");
      capability.SetCapability("browserstack.key", "YOUR_ACCESS_KEY");
      AndroidDriver<IWebElement> driver = new AndroidDriver<IWebElement>(new Uri("http://hub-cloud.browserstack.com/wd/hub"), capability);
      driver.Navigate().GoToUrl("https://web-push-book.gauntface.com/demos/notification-examples/");
      IWebElement ll = driver.FindElement(By.XPath("//*[@class='js-notification-overview' and text() = 'Example Notification']"));
      ll.Click();
      // To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
      driver.Context = ("NATIVE_APP");
      ll =  driver.FindElement(By.XPath(".//android.widget.Button[@text='Allow']"));
      ll.Click();
      Thread.Sleep(2000);
      driver.Quit();
    }
  }
}
import time
from appium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

desired_cap = {
  'device': 'Samsung Galaxy S10',
  'realMobile': 'true',
  'os_version': '9.0'
}
driver = webdriver.Remote(command_executor='http://YOUR_USERNAME:YOUR_ACCESS_KEY@hub.browserstack.com/wd/hub', desired_capabilities=desired_cap)
driver.get("https://web-push-book.gauntface.com/demos/notification-examples/")
driver.find_element_by_xpath("//*[@class='js-notification-overview' and text() = 'Example Notification']").click()
// To accept/block the popup, you need to switch the context to NATIVE_APP and click on the Allow/Block button.
driver.switch_to.context('NATIVE_APP')
driver.find_element_by_xpath(".//android.widget.Button[@text='Allow']").click()
time.sleep(2)
driver.quit()
require 'rubygems'
require 'appium_lib'

caps = {}
caps['device'] = 'Samsung Galaxy S10'
caps['realMobile'] = 'true'
caps['os_version'] = '9.0'
appium_driver = Appium::Driver.new({
  'caps' => caps,
  'appium_lib' => {
      :server_url => "http://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub"
  }}, true)
driver = appium_driver.start_driver
driver.navigate.to "https://web-push-book.gauntface.com/demos/notification-examples/"
driver.find_element(:xpath, "//*[@class='js-notification-overview' and text() = 'Example Notification']").click;
// To accept/block the popup, you need to switch the context to NATIVE_APP and click on the Allow/Block button.
driver.set_context('NATIVE_APP')
driver.find_element(:xpath, ".//android.widget.Button[@text='Allow']").click;
sleep(2)
driver.quit

Mobile-Only permission pop-ups

This section shows how you can automate scenarios involving app permission pop-ups—on real mobile devices.

1. “Storage access permission” pop-up on Android devices

You can test what happens when your web app is allowed to (or blocked from) accessing device storage on Android devices, in Automate.

storage_access_chrome

The snippet below lets you automate an ‘Allow’ or ‘Block’ interaction on Android devices when the remote Chrome browser asks for permission to access device storage.

import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;

import java.net.URL;

public class AllowFileDownloadPopupChromeMobile {
  public static final String AUTOMATE_USERNAME = "YOUR_USERNAME";
  public static final String AUTOMATE_KEY = "YOUR_ACCESS_KEY";
  public static final String URL = "https://" + AUTOMATE_USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub";

  public static void main(String[] args) throws Exception {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability("browser", "Chrome");
    caps.setCapability("browserName", "android");
    caps.setCapability("device", "Samsung Galaxy S10");
    caps.setCapability("realMobile", "true");
    caps.setCapability("os_version", "9.0");

    AppiumDriver driver = new AndroidDriver(new URL(URL), caps);
    driver.get("https://the-internet.herokuapp.com/download");
    driver.findElement(By.linkText("some-file.txt")).click();
    Thread.sleep(2000);

    // To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
    driver.context("NATIVE_APP");
    driver.findElement(By.xpath(".//android.widget.Button[@text='Continue']")).click();
    driver.findElement(By.xpath(".//android.widget.Button[@text='Allow']")).click();
    Thread.sleep(2000);
    driver.quit();
  }
}
let webdriver = require('wd');

let capabilities = {
  'os_version': '9.0',
  'device': 'Samsung Galaxy S10',
  'real_mobile': 'true',
  'browserstack.user' : 'YOUR_USERNAME',
  'browserstack.key' : 'YOUR_ACCESS_KEY'
}

let driver = webdriver.promiseRemote("http://hub-cloud.browserstack.com/wd/hub");
driver.init(capabilities, function() {
  driver.get('https://the-internet.herokuapp.com/download')
    .then(function() {
      (async () => {
        let element = await driver.element("xpath", "//*[text()='some-file.txt']");
        await element.click();

        // To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
        await driver.context('NATIVE_APP');
        let element2 = await driver.element("xpath", ".//android.widget.Button[@text='Continue']")
        await element2.click();
        let element3 = await driver.element("xpath", ".//android.widget.Button[@text='Allow']")
        await element3.click();
        await driver.quit();
      })();
    });
});
using System;
using OpenQA.Selenium;
using OpenQA.Selenium.Remote;
using System.Threading;
using OpenQA.Selenium.Appium.Android;

namespace SampleCSharp {
  class Program {
    static void Main(string[] args) {
      DesiredCapabilities capability = new DesiredCapabilities();
      capability.SetCapability("device", "Samsung Galaxy S10");
      capability.SetCapability("real_mobile", "true");
      capability.SetCapability("browserstack.user", "YOUR_USERNAME");
      capability.SetCapability("browserstack.key", "YOUR_ACCESS_KEY");

      AndroidDriver<IWebElement> driver = new AndroidDriver<IWebElement>(new Uri("http://hub-cloud.browserstack.com/wd/hub"), capability);
      driver.Navigate().GoToUrl("https://the-internet.herokuapp.com/download");
      IWebElement ll = driver.FindElement(By.XPath("//*[text()='some-file.txt']"));
      ll.Click();
      Thread.Sleep(2000);
      // To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
      driver.Context = ("NATIVE_APP");
      ll =  driver.FindElement(By.XPath(".//android.widget.Button[@text='Continue']"));
      ll.Click();
      ll =  driver.FindElement(By.XPath(".//android.widget.Button[@text='Allow']"));
      ll.Click();
      Thread.Sleep(2000);
      driver.Quit();
    }
  }
}
import time
from appium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

desired_cap = {
  'device': 'Samsung Galaxy S10',
  'realMobile': 'true',
  'os_version': '9.0'
}
driver = webdriver.Remote(command_executor='http://YOUR_USERNAME:YOUR_ACCESS_KEY@hub.browserstack.com/wd/hub', desired_capabilities=desired_cap)
driver.get("https://the-internet.herokuapp.com/download")
driver.find_element_by_xpath("//*[text()='some-file.txt']").click()
time.sleep(2)
# To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
driver.switch_to.context('NATIVE_APP')
driver.find_element_by_xpath(".//android.widget.Button[@text='Continue']").click()
driver.find_element_by_xpath(".//android.widget.Button[@text='Allow']").click()
time.sleep(2)
driver.quit()
require 'rubygems'
require 'appium_lib'

caps = {}
caps['device'] = 'Samsung Galaxy S10'
caps['realMobile'] = 'true'
caps['os_version'] = '9.0'
appium_driver = Appium::Driver.new({
  'caps' => caps,
  'appium_lib' => {
      :server_url => "http://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub"
  }}, true)
driver = appium_driver.start_driver
driver.navigate.to "https://the-internet.herokuapp.com/download"
driver.find_element(:xpath, "//*[text()='some-file.txt']").click;
sleep(2)
# To accept/block the popup, you need to switch the context to “NATIVE_APP“ and click on the Allow/Block button.
driver.set_context('NATIVE_APP')
driver.find_element(:xpath, ".//android.widget.Button[@text='Continue']").click;
driver.find_element(:xpath, ".//android.widget.Button[@text='Allow']").click;
sleep(2)
driver.quit

2. Automatically grant all app permissions for Android apps

The autoGrantPermissions is an Appium capability. When enabled, your Android app gets all the permissions listed in the manifest file of the APK, upon install.

The sample below shows how to enable autoGrantPermissions capability for your test:

caps.setCapability("autoGrantPermissions", "true");
capabilities['autoGrantPermissions'] = true;
capability.SetCapability("autoGrantPermissions", "true");
desired_cap["autoGrantPermissions"] = "true"
caps['autoAcceptAlerts'] = 'true'

3. Allow / Deny all app permissions for iOS apps

autoAcceptAlerts and autoDismissAlerts are Appium capabilities. When enabled, the iOS device accepts (or rejects) all access requests, upon install. This includes location, contacts, photos, and more.

Note: These capabilities do not work on XCUITest scripts.

The sample below shows how to enable autoAcceptAlerts or autoDissmissAlerts capabilities for your test:

caps.setCapability("autoAcceptAlerts", "true");
//OR
caps.setCapability("autoDissmissAlerts", "true");
capabilities['autoAcceptAlerts'] = true;
// OR
capabilities['autoDissmissAlerts'] = true;
capability.SetCapability("autoAcceptAlerts", "true");
//OR
capability.SetCapability("autoDissmissAlerts", "true");
desired_cap["autoAcceptAlerts"] = "true"
#OR
desired_cap["autoDissmissAlerts"] = "true"
caps['autoAcceptAlerts'] = 'true'
#OR
caps['autoDissmissAlerts'] = 'true'

4. Allow / Deny any app permission pop-up on Android and iOS devices

For more selective test scenarios, you would want to accept some app permission pop-ups and deny the others. To automate these interactions, you can switch to “NATIVE_APP” context to ‘accept’ or ‘deny’ each pop-up on iOS and Android devices.

driver.context("NATIVE_APP");
//For Android
driver.findElement(By.xpath(".//android.widget.Button[@text='Allow']")).click();
//For iOS
driver.findElement(By.id("Allow")).click();
await driver.context('NATIVE_APP');
//For Android
let element = await driver.element("xpath", ".//android.widget.Button[@text='Continue']")
await element.click();
//For iOS
let element = await driver.element("id", "Allow")
await element.click();
driver.Context = ("NATIVE_APP");
//For Android
IWebElement ll =  driver.FindElement(By.XPath(".//android.widget.Button[@text='Continue']"));
ll.Click();
//For iOS
IWebElement ll =  driver.FindElement(By.Id("Allow"));
ll.Click();
driver.switch_to.context('NATIVE_APP')
#For Android
driver.find_element_by_xpath(".//android.widget.Button[@text='Allow']").click()
#For iOS
driver.find_element_by_id("Allow").click()
driver.set_context('NATIVE_APP')
#For Android
driver.find_element(:xpath, ".//android.widget.Button[@text='Allow']").click;
#For iOS
driver.find_element(:id, "Allow").click;

Exception

Disabling ‘Save your password’ message doesn’t work in Edge browser.

There is a known issue in Edge browser which prevents you from interacting with OR disabling the ‘Save Your Password’ pop-up. Refer to the GitHub issue link for more details.