如何使用Selenium Webdriver在浏览器中处理“地理位置"弹出窗口? [英] How can I handle Geo Location popup in browser using selenium webdriver?

查看:436
本文介绍了如何使用Selenium Webdriver在浏览器中处理“地理位置"弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在弹出窗口中单击共享位置"按钮来共享我的位置.如何使用Selenium WebDriver处理此问题?请参考下图.

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. 导航到此URL
  2. 单击右侧的Try it按钮
  3. 位置弹出窗口将显示为:

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

推荐答案

所以说如果要启动任何站点,就会弹出此GeoLocation,您不能与该元素进行交互,因为它不是WebElement,因此您必须在浏览器启动网站之前进行处理,因此以下是启动浏览器所需设置的属性:-

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:-

对于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);

对于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);

希望有帮助!

这篇关于如何使用Selenium Webdriver在浏览器中处理“地理位置"弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆