![](/img/trans.png)
[英]How to dismiss/accept Device Location Popup on Android devices - Selenium with Browser stack
[英]How to handle allow/dismiss geo location popup on Android devices
我想知道如何在 Android 设备上处理地理位置弹出窗口
下面是一些高级细节
我已经尝试了所有可能的方法来处理这个问题,附件是我尝试过的代码片段
最初我认为这是一个警报并试图通过切换到警报来处理
driver.switchTo().alert().dismiss();
然后我尝试使用配置文件,但它适用于 Windows,但不适用于 android
ChromeOptions options = new ChromeOptions();
DesiredCapabilities caps = DesiredCapabilities.android();
HashMap<String, Object> contentSettings = new HashMap<String, Object>();
HashMap<String, Object> profile = new HashMap<String, Object>();
HashMap<String, Object> prefs = new HashMap<String, Object>();
System.out.println("setting chrome options");
contentSettings.put("geolocation", 1);
profile.put("managed_default_content_settings", contentSettings);
prefs.put("profile", profile);
options.setExperimentalOption("prefs", prefs);*/
caps.setCapability(ChromeOptions.CAPABILITY, options);
driver = new RemoteWebDriver(new URL(pcUrl), caps);
然后我尝试提供一些选项,这也无法处理弹出窗口
options.addArguments("start-maximized");
options.addArguments("test-type");
options.addArguments("enable-strict-powerful-feature-restrictions");
options.addArguments("disable-geolocation");
caps.setCapability(ChromeOptions.CAPABILITY, options);
caps = caps.merge(DesiredCapabilities.chrome());
driver.context("NATIVE_APP");
driver.findElement(By.xpath(".//android.widget.Button[@text='Allow']")).click();
但是我无法将 AndriodDriver 输入到 RemoteWebDriver,对此有任何建议
或者如果有任何其他可能的方法来实现这一点,请告诉我。
您可以通过创建 Appium 会话来驱动 Mobile Chrome 而不是 Selenium 来实现这一点。 这应该允许您像在 Selenium 测试中一样与元素进行交互,但也可以更改为NATIVE_APP
上下文以执行诸如关闭弹出窗口之类的操作。
您需要进行一些更改:
AndroidOptions
实例而不是ChromeOptions
,然后将browserName
功能设置为Chrome
AppiumDriver
类型的WebElement
代替RemoteWebDriver
我能够运行会话并关闭弹出窗口,如下所示:
AndroidOptions options = new AndroidOptions();
options.setCapability("deviceName","Google Pixel 3a GoogleAPI Emulator" );
options.setCapability("platformVersion", "11.0");
options.setCapability("automationName", "UIAutomator2");
options.setCapability("browserName", "Chrome");
Map<String, Object> sauceOptions = new HashMap<>();
sauceOptions.put("name", "WW");
sauceOptions.put("appiumVersion", "1.20.2");
options.setCapability("sauce:options", sauceOptions);
AppiumDriver<WebElement> driver = new AppiumDriver<WebElement>(new URL(address),options);
driver.context("NATIVE_APP");
driver.findElement(By.xpath(".//android.widget.Button[@text='Allow']")).click();
您可能还必须关闭 Android 本身的第二个弹出窗口:
driver.findElement(By.xpath(".//android.widget.Button[@text='While using the app']")).click();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.