Great Question Great Question - 1 year ago 202
AngularJS Question

How to select a button on popup using Protractor

When the user navigates to the page, a small popup window appears asking the user to "Share Location" like in the screen shot below.
enter image description here

So I wonder how can I use Protractor to simulate the user's click on the "Share Location" button (apparently,

element(by.buttonText("Share Location")).click();
doesn't work).

Also the browser in this screenshot is Firefox and as different browser may have different messages/styles how can I then tackle this issue?

Answer Source

The problem is that this button is not in the DOM and you cannot control it with protractor/selenium. You need to avoid it being opened in the first place and let the browser know how to automatically respond.

Applying the solution in this answer (not tested):

browser.executeScript("navigator.geolocation.getCurrentPosition = function(success) { success({coords: {latitude: 50.455755, longitude: 30.511565}}); }");

You can also solve it by setting the geo.prompt.testing and geo.prompt.testing.allow to true in the FirefoxProfile preferences. Sample protractor config with a makeFirefoxProfile() helper function:

var q = require("q");
var FirefoxProfile = require("firefox-profile");

var makeFirefoxProfile = function(preferenceMap, specs) {
    var deferred = q.defer();
    var firefoxProfile = new FirefoxProfile();

    for (var key in preferenceMap) {
        firefoxProfile.setPreference(key, preferenceMap[key]);

    firefoxProfile.encoded(function (encodedProfile) {
        var capabilities = {
            firefox_profile: encodedProfile,
            specs: specs

    return deferred.promise;

exports.config = {
    getMultiCapabilities: function() {
        return q.all([
                {"geo.prompt.testing": true, "geo.prompt.testing.allow": true},

    // ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download