Appium版本为1.9.0
Java客户端版本为1.6.1
Android Studio版本3.2
chrome驱动程序版本为 ChromeDriver 2.42
Android移动设备Chrome浏览器版本为69.0,而Android版本为6.0
以下是我尝试切换子窗口的代码
Set<String> windows = driver.getWindowHandles(); // Get all windows working fine
String parentWindow = windows.stream().findFirst().get(); // Get parent window
Thread.sleep(15000); // Adding static time due to page loading issue
driver.switchTo().window(windows.toArray()[windows.toArray().length-1].toString());
切换到子窗口。也
windows.toArray([windows.toArray().length-1].toString()
给出正确的值,但如果将其放在driver.switchTo.window上,则会抛出异常以下的情况
例外
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: unknown error: 'name' must be a string
(Session info: chrome=69.0.3497.100)
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64)
Build info: version: '3.14.0', revision: 'aacccce0', time: '2018-08-02T20:05:20.749Z'
System info: host: '-PC', ip: '172.16.2.99', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_171'
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {app: D:\Drive 20-08-2018\H..., appActivity: com.ss.dd.M..., appPackage: com.rr.rr, autoGrantPermissions: true, automationName: Appium, chromedriverExecutable: D:\Drive 20-08-2018\H..., databaseEnabled: false, desired: {app: D:\Drive 20-08-2018\H..., appActivity: com.ii.M..., appPackage: com.pkg, autoGrantPermissions: true, automationName: Appium, chromedriverExecutable: D:\Drive 20-08-2018\H..., deviceName: InFocus InFocusM500, nativeWebScreenshot: true, newCommandTimeout: 1200, noReset: true, platform: ANDROID, platformName: android}, deviceManufacturer: Infocus, deviceModel: InFocus M500, deviceName: 17789703032114619539, deviceScreenSize: 480x854, deviceUDID: 17789703032114619539, javascriptEnabled: true, locationContextEnabled: false, nativeWebScreenshot: true, networkConnectionEnabled: true, newCommandTimeout: 1200, noReset: true, platform: ANDROID, platformName: Android, platformVersion: 6.0, takesScreenshot: true, warnings: {}, webStorageEnabled: false}
Session ID: 4cd7a579-8606-43e8-922b-5a97a6157053
at com.hp.commercial.framework.common.TestScriptManager.handleTestFailure(TestScriptManager.java:791)
at com.fd.fdf.fdf.testscripts.fdf.fdf(fd.java:616)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
答案 0 :(得分:0)
您可以尝试使用stream
API
driver.switchTo().window(windows.stream().skip(windows.size()- 2).findFirst().get());
答案 1 :(得分:0)
您可以尝试一下吗?
String childWindow = (String) windows.toArray()[windows.toArray().length-1];
driver.switchTo().window(childWindow);