【发布时间】:2021-11-25 22:31:52
【问题描述】:
我想知道如何处理 Android 设备上的地理位置弹出窗口
以下是一些高级细节
- 我正在使用 Saucelabs 云来运行我的脚本
- 我使用的是 Chrome 浏览器
- Android 模拟器:三星 Galaxy S8 Plus 高清 GoogleAPI 模拟器 Android-真实设备:Samsung_Galaxy_S10_POC173
- 测试环境:Selenium、Java、testNg
我已经尝试了所有可能的方法来处理这个问题,附上我尝试过的代码sn-ps
最初我认为这是一个警报,并试图通过切换到警报来处理
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,对此有任何建议
或者如果有任何其他可能的方式来实现这一点,请告诉我。
【问题讨论】:
标签: java selenium-webdriver appium saucelabs