1

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?

NarendraR
  • 7,577
  • 10
  • 44
  • 82
LeBronPark
  • 15
  • 1
  • 4
  • Hi, Welcome to stack overflow. Please refer the [ask] link for more details on how to ask a question and update your question accordingly. – Jeroen Heier Jul 20 '17 at 04:02

3 Answers3

2

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);
demouser123
  • 4,108
  • 9
  • 50
  • 82
  • OP's question is about `add allow site` :) but your code is disabling it. Thanks – undetected Selenium Jul 20 '17 at 04:03
  • Thank you for answer. can i ask one more? "prefs" is only working on DeskTop Chrome. How do i have to do on Mobile Chrome? – LeBronPark Jul 20 '17 at 04:30
  • @DebanjanB OP's talks about `rid of the popup on my testing` which leads me to believe he wants to ignore/disable this. – demouser123 Jul 20 '17 at 06:46
  • @LeBronPark you can use Mobile Emulation to achieve this. [Here](https://sites.google.com/a/chromium.org/chromedriver/mobile-emulation) is a link for same. – demouser123 Jul 20 '17 at 06:49
  • @demouser123 You are right (+1) Can you help me to set it `Allow` (always)? Thanks – undetected Selenium Jul 20 '17 at 07:36
  • does work? this code doesn't work on chrome of android. https://bugs.chromium.org/p/chromedriver/issues/detail?id=1015&can=1&q=prefs%20android&colspec=ID%20Status%20Pri%20Owner%20Summary – LeBronPark Jul 20 '17 at 11:02
1

Use chrome devtools protocol can do this.Browser.grantPermission allow to config the geolocation permission before accessing the target website. You can look at my another answer for more detail Setting sensors (location) in headless Chrome .

linw1995
  • 166
  • 1
  • 8
0

The below code snippet working for me to disable that pop up. Instead of profile.default_content_settings.geolocation,

I used profile.default_content_setting_values.notifications.

ChromeOptions options = new ChromeOptions();

JSONObject jsonObject = new JSONObject();
jsonObject.put("profile.default_content_setting_values.notifications", 1);

options.setExperimentalOption("prefs", jsonObject);
WebDriver driver = new ChromeDriver(options);

or

DesiredCapabilities caps = new DesiredCapabilities();
ChromeOptions options = new ChromeOptions();

Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
prefs.put("profile.default_content_setting_values.notifications", 1);

options.setExperimentalOption("prefs", prefs);
caps.setCapability(ChromeOptions.CAPABILITY, options);
jithinkmatthew
  • 890
  • 8
  • 17