title: Appium/wdio - unable to dismiss location permissions alert on Android
body: <p>I'm using <a href="https://webdriver.io/" rel="nofollow noreferrer">webdriver.io</a> to write a suite of <a href="http://appium.io/" rel="nofollow noreferrer">Appium</a> tests for a hybrid <a href="https://cordova.apache.org/" rel="nofollow noreferrer">Cordova</a> App.</p>
  
  <pre><code>"appium": "^1.10.0",
  "wdio-appium-service": "^0.2.3",
  "wdio-jasmine-framework": "^0.3.8",
  "webdriverio": "^4.14.1",
  </code></pre>
  
  <p><strong>In one of my tests</strong> I am trying to programmatically <strong>accept</strong> the <strong>Location Permissions native modal</strong> presented on App launch on top of the WebView.</p>
  
  <p>I can easily do so in iOS using <a href="http://v4.webdriver.io/v4.12/api/protocol/alertAccept.html" rel="nofollow noreferrer">browser.alertAccept()</a> but the latter does not seem to work for Android.</p>
  
  <p>I also tried to switch to the native context to dismiss it but had no luck.</p>
  
  <pre><code>function dismissLocationPermissions() {
    if (browser.isAndroid) {
      new WebView().switchToContext(0);
      browser.pause(2000);
      const ANDROID_ACCEPT_ALERT_SELECTOR = "//*[@class='android.widget.Button'][2]";
      // OR '*//android.widget.Button[@text="ALLOW"]' ?
      $(ANDROID_ACCEPT_ALERT_SELECTOR).click();
      WebView().switchToContext(1);
    } else {
      browser.alertAccept();
    }
  }
  </code></pre>
  
  <p>How can I dismiss the native alert on Android using wdio?</p>
  
  <p><a href="https://i.stack.imgur.com/vM8zO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vM8zO.png" alt="enter image description here"></a></p>