【发布时间】:2018-05-24 05:20:03
【问题描述】:
我正在尝试在真实的 iOS 设备上运行我的 Appium 测试。但是,我不知道如何在 Safari 上的选项卡之间切换。我使用 Appium IOSDriver 实例在 Safari 上打开一个页面。然后,我单击页面上的一个链接,该链接将打开一个新选项卡。现在我希望关闭此选项卡或至少切换回原来的窗口。
我尝试了以下解决方案,但似乎都没有帮助:
-
执行触摸操作打开选项卡界面,没有设法点击选项卡选项。
TouchAction ta = new TouchAction(driver); int h=driver.manage().window().getSize().getHeight(); int w=driver.manage().window().getSize().getWidth(); ta.tap(h-50,w-50).perform(); -
尝试切换回原始上下文,没有帮助
for (String contextName : contextNames) { if(!contextName.equals(original)) { WebViewContext = contextName; ((AppiumDriver) driver).context(WebViewContext); Thread.sleep(4000); driver.close(); } } -
试过Javascript,没有成功
Set<String> windows = driver.getWindowHandles(); String currentHandle = driver.getWindowHandle(); ((JavascriptExecutor)driver).executeScript("window.open();"); Set<String> newWindow = driver.getWindowHandles(); newWindow.removeAll(windows); driver.switchTo().window(original);
【问题讨论】:
标签: java safari appium appium-ios