英文:
Driver returns null value : appium
问题
我有以下代码,我正在其中搜索当前活动中的元素。然而,驱动程序正在返回空值。
try
{
String ca = ((AndroidDriver) driver).currentActivity();
}
catch(Exception e)
{
System.out.println(e.getCause());
e.getMessage();
e.printStackTrace();
}
日志:
java.lang.ClassCastException:类io.appium.java_client.AppiumDriver无法转换为io.appium.java_client.android.AndroidDriver(io.appium.java_client.AppiumDriver和io.appium.java_client.android.AndroidDriver在' app '加载程序的未命名模块中)
我尝试将driver的转换更改为AppiumDriver。即使这样也不起作用,问题是什么?
英文:
I have this following code where I am searching for an element in current activity. However, the driver is returning null value.
try
{
String ca = ((AndroidDriver) driver).currentActivity();
}
catch(Exception e)
{
System.out.println(e.getCause());
e.getMessage();
e.printStackTrace();
}
Logs :
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')
I tried changing the driver cast to AppiumDriver. Does not work even then,whats the issue here?
答案1
得分: 1
请注意您定义驱动实例的方式,不要使用通用的 AppiumDriver
,避免进行类型转换:
AndroidDriver driver = new AndroidDriver(appiumURL, capabilities);
...
String cActivity = driver.currentActivity();
运行得非常完美。
英文:
Double check the way you defined the driver instance, don't use generic AppiumDriver
and avoid casting:
AndroidDriver driver = new AndroidDriver(appiumURL, capabilities);
...
String cActivity = driver.currentActivity();
works perfectly.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论