Java 驱动程序返回空值:appium
我在下面的代码中搜索当前活动中的元素。但是,驱动程序返回空值Java 驱动程序返回空值:appium,java,appium,Java,Appium,我在下面的代码中搜索当前活动中的元素。但是,驱动程序返回空值 try { String ca = ((AndroidDriver) driver).currentActivity(); } catch(Exception e) { System.out.println(e.getCause()); e.getMessage(); e.printStackTrace(); } 日志: java.lan
try
{
String ca = ((AndroidDriver) driver).currentActivity();
}
catch(Exception e)
{
System.out.println(e.getCause());
e.getMessage();
e.printStackTrace();
}
日志:
java.lang.ClassCastException: class io.appium.java_client.AppiumDriver cannot be cast to class io.appium.java_client.android.AndroidDriver (io.appium.java_client.AppiumDriver and io.appium.java_client.android.AndroidDriver are in unnamed module of loader 'app')
我尝试将驱动程序转换为AppiumDriver。即使这样也不起作用,这里有什么问题?请仔细检查您定义驱动程序实例的方式,不要使用通用
AppiumDriver
,并避免强制转换:
AndroidDriver=newandroiddriver(appiumURL,能力);
...
字符串cActivity=driver.currentActivity();
工作完美