Is there a way to bypass Chrome geolocation dialog

2019-08-20 07:00发布

I faced this problem, when automating an application with protractor.

Once I open a home page I get geolocation dialog with Block/Allow buttons, which didn't let proceed without selection either option

enter image description here

It turned out, that this dialog is not an instance of alert, that's why browser.switchTo().alert().confirm() didn't work

Passing '--disable-notifications' argument to Chrome also didn't solve the problem

Research online didn't give any positive results. How to solve it?

1条回答
兄弟一词,经得起流年.
2楼-- · 2019-08-20 07:16

The solution to the problem is to pass "prefs": {'profile.default_content_setting_values.geolocation': 2} to capabilities object in your protractor.config.js

Below is another option that does pretty much the same thing.

So chrome may take an argument --user-data-dir=/tmp/chrome which specifies profile to open chrome with. If profile doesn’t exist at specified directory it creates default one. Then if you open /tmp/chrome/Default/Preferences you’ll see an object with preferences. You needed to set default_content_setting_values.geolocation to 2 (not 1 or 0) to make it NOT prompt that dialog

查看更多
登录 后发表回答