如何使用Selenium Webdriver在浏览器中处理“地理位置"弹出窗口? [英] How can I handle Geo Location popup in browser using 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:
- 导航到此URL
- 单击右侧的
Try it
按钮 -
位置弹出窗口将显示为:
- Navigate to this URL
- Click on
Try it
button from right section 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屋!