Search code examples
seleniumselenium-chromedriverselendroid

How to add allow site on location of chrome content setting with selenium


I want to add site "a.com" on mobile chrome using selenium. Option - [Advanced-content setting-location-ask before accessing-allow site]

Because i want to rid of the popup on my testing

enter image description here

Does anyone know?


Solution

  • To disable chrome asking for location you need to use ChromeOptions and disable geolocation from profile settings

     ChromeOptions options = new ChromeOptions();
    
     JSONObject jsonObject = new JSONObject();
     jsonObject.put("profile.default_content_settings.geolocation", 2);
    
     options.setExperimentalOption("prefs", jsonObject);
     WebDriver driver = new ChromeDriver(options);
    

    Please see that the whole answer is already explained in this SO post.

    Edit : In case, the option is to be kept enabled, you just need to change this line

    jsonObject.put("profile.default_content_settings.geolocation", 2);
    

    to

    jsonObject.put("profile.default_content_settings.geolocation", 1);