I have a PWA (which means essentially a webpage + serviceworker) that asks for the user's camera and location via getUserMedia and getCurrentPosition calls. These create an OS level dialog box with options to Allow | Deny. It appears that Selenium driver cannot manipulate these dialogs. Is there any way to get past the dialog's using Selenium's RemoteWebDriver? The objective is to run the webpage on mobile devices using a service like BrowserStack.

  • Is your app a native or web app? Sep 7 '19 at 5:22
  • Its a web app, a webpage with a serviceworker basically
    – patrick
    Sep 8 '19 at 1:11

The trick is to flip the driver into NATIVE_APP mode (this seemed a bit dubious since I have a normal webpage, but it worked)

Here's a test console app for dot net framework 4.
On some phones 'Allow' might be 'ALLOW' and the XPath matching is case sensitive

Note: if you are using BrowserStack and run out of minutes you have to choose the 'Automate Mobile' plan, their pricing page is highly confusing

static void Main(string[] args)
        DesiredCapabilities capability = new DesiredCapabilities();
        capability.SetCapability("device", "Samsung Galaxy S9");
        capability.SetCapability("real_mobile", "true");
        capability.SetCapability("browserstack.user", username);
        capability.SetCapability("browserstack.key", password);

        capability.SetCapability("autoAcceptAlerts", "true");
        capability.SetCapability("autoGrantPermissions", "true");

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

        driver.Context = ("NATIVE_APP");  // this does the trick <<<< 

        IWebElement ll = driver.FindElement(By.XPath("//*[text()='some-file.txt']"));

        // 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 = driver.FindElement(By.XPath(".//android.widget.Button[@text='ALLOW']"));


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.