java如何处理Android设备上的允许/取消地理位置弹出窗口
我想知道如何处理Android设备上的地理位置弹出窗口
下面是一些高层细节
- 我正在使用Saucelabs云来运行我的脚本
- 我正在使用Chrome浏览器
- Android仿真器:三星Galaxy S8 Plus高清GoogleAPI仿真器 Android-realdevice:Samsung_Galaxy_S10_POC173
- 测试环境:Selenium、Java、testNg
我已经尝试了所有可能的方法来处理这个问题,附件是我尝试过的代码片段
起初,我认为这是一个警报,并试图处理切换到警报
driver.switchTo().alert().dismiss();
然后我尝试了配置文件,但它在windows上运行良好,但在安卓上运行不好
ChromeOptions options = new ChromeOptions();
DesiredCapabilities caps = DesiredCapabilities.安卓();
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(".//安卓.widget.Button[@text='Allow']")).click();
但我无法向RemoteWebDriver键入cast和rioddriver,对此有何建议
或者,如果有任何其他可能的方式来实现这一点,请让我知道
# 1 楼答案
您可以通过创建一个Appium会话来驱动移动Chrome,而不是Selenium。这应该允许您像在Selenium测试中那样与元素进行交互,但也可以更改为
NATIVE_APP
上下文来执行诸如取消弹出窗口之类的操作您需要做一些更改:
AndroidOptions
的实例而不是ChromeOptions
,然后将browserName
功能设置为Chrome
WebElement
的AppiumDriver
而不是RemoteWebDriver
我可以运行一个会话并关闭弹出窗口,如下所示:
您可能还需要关闭Android本身的第二个弹出窗口: