司机返回空值:appium

huangapple go评论61阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2020年10月1日 17:32:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/64152608.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定