3

I want to share my location on click of 'Share Location' button on the popup. How can I handle this using selenium webdriver? Refer image below.

Steps to reach to Location popup:

  1. Navigate to this URL
  2. Click on Try it button from right section
  3. Location popup will be displayed as :

    https

Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73
Sameer D
  • 31
  • 1
  • 1
  • 2
  • 2
    Possible duplicate of [How do I enable geolocation support in chromedriver for Selenium?](http://stackoverflow.com/questions/8411816/how-do-i-enable-geolocation-support-in-chromedriver-for-selenium) – Florent B. Aug 04 '16 at 13:10
  • you want to remove this popup? – Paras Aug 04 '16 at 13:40
  • @SaurabhGaur: I am Currently working on e-commerce project and any user is logged in, it is mandatory to check the current location. That is why I need to handle this popup? So, how can I click on 'Share Location' button in popup? – Sameer D Aug 04 '16 at 13:44
  • @SameerD this can not be possible by selenium to click on `Share Location` button, you need to create custom profile with allow share location, [have a look on this link](http://stackoverflow.com/questions/28390611/how-can-i-allow-location-access-using-selenium) for for information – Saurabh Gaur Aug 04 '16 at 13:54
  • @pArAs: I want to remove this popup, but using selenium webdriver. – Sameer D Aug 05 '16 at 05:01

2 Answers2

11

So lets say if for launching any site, this GeoLocation pop up comes, You can't interact with this element as its not a WebElement, so you have to handle it before the browser launches a site so below are the properties you need to set to launch the browser:-

For Firefox:

FirefoxProfile geoDisabled = new FirefoxProfile();
geoDisabled.setPreference("geo.enabled", false);
geoDisabled.setPreference("geo.provider.use_corelocation", false);
geoDisabled.setPreference("geo.prompt.testing", false);
geoDisabled.setPreference("geo.prompt.testing.allow", false);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, geoDisabled);
driver = new FirefoxDriver(capabilities);

For Chrome:

ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
options.addArguments("test-type");
options.addArguments("enable-strict-powerful-feature-restrictions");
options.addArguments("disable-geolocation");
cap.setCapability(ChromeOptions.CAPABILITY, options);
cap = cap.merge(DesiredCapabilities.chrome());
driver = new ChromeDriver(cap);

Hope it helps!

Anna Ira Hurnaus
  • 1,680
  • 3
  • 19
  • 29
Paras
  • 3,197
  • 2
  • 20
  • 30
1
    FirefoxProfile geoDisabled = new FirefoxProfile();
    geoDisabled.setPreference("geo.enabled", false);
    geoDisabled.setPreference("geo.provider.use_corelocation", false);
    geoDisabled.setPreference("geo.prompt.testing", false);
    geoDisabled.setPreference("geo.prompt.testing.allow", false);
    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    capabilities.setCapability(FirefoxDriver.PROFILE, geoDisabled);

    WebDriver driver;
    System.setProperty("Driver_Name", "Driver_path");
    driver =new FirefoxDriver(geoDisabled);

Need to pass the instance of FirefoxProfile.