司机返回空值:appium

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

Driver returns null value : appium

问题

我有以下代码,我正在其中搜索当前活动中的元素。然而,驱动程序正在返回空值。

  1. try
  2. {
  3. String ca = ((AndroidDriver) driver).currentActivity();
  4. }
  5. catch(Exception e)
  6. {
  7. System.out.println(e.getCause());
  8. e.getMessage();
  9. e.printStackTrace();
  10. }

日志:

  1. java.lang.ClassCastException:类io.appium.java_client.AppiumDriver无法转换为io.appium.java_client.android.AndroidDriverio.appium.java_client.AppiumDriverio.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.

  1. try
  2. {
  3. String ca = ((AndroidDriver) driver).currentActivity();
  4. }
  5. catch(Exception e)
  6. {
  7. System.out.println(e.getCause());
  8. e.getMessage();
  9. e.printStackTrace();
  10. }

Logs :

  1. 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,避免进行类型转换:

  1. AndroidDriver driver = new AndroidDriver(appiumURL, capabilities);
  2. ...
  3. String cActivity = driver.currentActivity();

运行得非常完美。

英文:

Double check the way you defined the driver instance, don't use generic AppiumDriver and avoid casting:

  1. AndroidDriver driver = new AndroidDriver(appiumURL, capabilities);
  2. ...
  3. 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:

确定