I am trying to use Selenium in Java to get the user's geographical coordinates, but using IP address isn't accurate enough, so i wanted to use this website <http://www.whataremycoordinates.com/> , but it isn't working, and I am guessing it is because you have to allow location use, so is there anyway I can allow location use in Selenium, or maybe some other way to get exact geographical coordinates
['https://Stackoverflow.com/questions/28390611', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4542233/']
Usually, when a site wants to get this kind of data, a browser asks you if you want to share your location. The question is inside a popup which *cannot be controlled* with `selenium`. In this case, you need to tell the browser, not to open the popup and allow to share your location at the same time so that the popup would not be opened in the first place.

For `Firefox`, you need to:

* open the site
* allow to share your location (you can also check `about:permissions` to see the setting)
* save the current firefox profile
* start firefox with `FirefoxProfile` pointing to the profile you've saved before

For more information, see:

* [Custom Firefox Profile for Selenium](http://www.toolsqa.com/selenium-webdriver/custom-firefox-profile/)
* [How to open specified profile Firefox with Selenium 2 Webdriver?](https://stackoverflow.com/questions/20543013/how-to-open-specified-profile-firefox-with-selenium-2-webdriver)
* [How to use custom Firefox Profile with Selenium? (Java) (And pass HTML Authorization Window)](https://stackoverflow.com/questions/14458289/how-to-use-custom-firefox-profile-with-selenium-java-and-pass-html-author)
* [Change GeoLocation using Selenium WebDriver in Firefox](http://techyworks.blogspot.com/2013/10/change-geolocation-using-selenium.html)
* [Webdriver: Click "Share Location" button in Firefox](https://stackoverflow.com/questions/3859935/webdriver-click-share-location-button-in-firefox)
you can inject firefox profile at the time of creating driver

selenium 3 I am using if you are using selenium 2 no need for firefoxOptions you can directly pass the profile into driver.

lat-log-json:[How to enable geolocation permissions for a website in firefox profile using selenium webdriver](https://stackoverflow.com/questions/34740547/how-to-enable-geolocation-permissions-for-a-website-in-firefox-profile-using-sel)

```
FirefoxOptions opt = getFirefoxOptions();
WebDriver webDriver = new FirefoxDriver(opt);

//method for fire fox profile//////////////////////////////////
     public static FirefoxProfile getFirefoxProfile() {

            ProfilesIni profileIni = new ProfilesIni();
            FirefoxProfile profile = profileIni.getProfile("webDriverProfile");

            System.out.println("profile is null : " + (profile == null));
            if (profile == null) {
                profile = new FirefoxProfile();
            }

            profile.setPreference("browser.download.folderList", 2);
            profile.setPreference("browser.download.dir", "download/path");
            profile.setPreference(
                    "browser.helperApps.neverAsk.saveToDisk",
                    "application/pdf,application/octet-stream,"
                            + "application/download,text/html,application/xhtml+xml");
            profile.setPreference("pdfjs.disabled", true);
    //      profile.setPreference("dom.webnotifications.enabled", true);
            profile.setPreference("geo.enabled", true);
            profile.setPreference("geo.provider.use_corelocation", true);
            profile.setPreference("geo.prompt.testing", true);
            profile.setPreference("geo.prompt.testing.allow", true);
            profile.setPreference("geo.wifi.uri", "path-to-loglatjson\\geo-location-ITPL.json");
            // profile.setPreference("browser.helperApps.neverAsk.openFile",
            // "application/pdf");
            // profile.setPreference("browser.helperApps.alwaysAsk.force", false);
            /*
             * profile.setPreference("browser.download.manager.alertOnEXEOpen",
             * false);
             * profile.setPreference("browser.download.manager.focusWhenStarting",
             * false); profile.setPreference("browser.download.manager.useWindow",
             * false);
             * profile.setPreference("browser.download.manager.showAlertOnComplete",
             * false);
             * profile.setPreference("browser.download.manager.closeWhenDone",
             * false);
             */
            return profile;
        }

```