Chrome profile to disable “Know your location” pop

2019-02-28 02:13发布

I am running my tests in Google Chrome using chromedriver.exe binary. At one particular page this pop up comes which doesn't intervene/effect with the test but client doesn't want to see it. Possible reason could be, at the failure of test case it will capture the screenshot along with this pop up.

How can I create a chrome profile or capabilities which would disable this pop up?

enter image description here

Something like this:

ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=C:/Users/user_name/AppData/Local/Google/Chrome/User Data");

Edit:

This code stopped the "Know your location" pop up to come but generated another pop up. So its only partially working. options.addArguments("--enable-strict-powerful-feature-restrictions"); driver = new ChromeDriver(options);

enter image description here

4条回答
【Aperson】
2楼-- · 2019-02-28 02:53

Use --disable-geolocation, Chrome Options as given below:

options.addArguments("--disable-geolocation");

Also list of chrome command-line switches can be found in the below link:

http://peter.sh/experiments/chromium-command-line-switches/

查看更多
Emotional °昔
3楼-- · 2019-02-28 02:59

Declaring in the following way worked for me.

// Declare variables
 ChromeOptions options = new ChromeOptions();
 Map<String, Object> prefs = new HashMap<String, Object>();
 Map<String, Object> profile = new HashMap<String, Object>();
 Map<String, Object> contentSettings = new HashMap<String, Object>();
// Specify the ChromeOption we need to set
 contentSettings.put(“geolocation”, 1);
 profile.put(“managed_default_content_settings”, contentSettings);
 prefs.put(“profile”, profile);
 options.setExperimentalOption(“prefs”, prefs);
// Declare the capability for ChromeOptions
 caps.setCapability(ChromeOptions.CAPABILITY, options);
查看更多
孤傲高冷的网名
4楼-- · 2019-02-28 03:05

This code solved my problem with geolocation

options.AddUserProfilePreference("profile.default_content_setting_values.geolocation", 2);
查看更多
仙女界的扛把子
5楼-- · 2019-02-28 03:08

Add this below command line argument, which will restrict geolocation feature.

String url = "http://ctrlq.org/maps/where/";

//Chromedriver Version : 2.19.346078
System.setProperty("webdriver.chrome.driver", "CHROMEDRIVERPATH");

ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--enable-strict-powerful-feature-restrictions");

WebDriver driver = new ChromeDriver(options);
driver.get(url);

And other way is after lauching the chrome browser, Through the selenium code implement below steps which will disable the geo location popup.

  • Go to : chrome://settings/content

  • Under the location select 'Do not allow any site to track your physical location' option.

Do not allow any site to track your physical location

  • Click On Done
查看更多
登录 后发表回答