How do I enable geolocation support in chromedriver?

In the known issues section of the chromedriver wiki they said that you Cannot specify a custom profile

This is why it seems to me that @Sotomajor answer about using profile with Chrome as you would do with firefox will not work.

In one of my integration tests I faced the same issue. But because I was not bothering about the real geolocation values, all I had to do is to mock window.navigator.gelocation

In you java test code put this workaround to avoid Chrome geoloc permission info bar.

chromeDriver.executeScript("window.navigator.geolocation.getCurrentPosition = function(success) {
  var position = {
    "coords": {
      "latitude": "555",
      "longitude": "999"
    }
  };
  success(position);
}");

latitude (555) and longitude (999) values here are just test value

Leave a Comment