java AndroidDriver 无法解析为类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25221701/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 07:36:44  来源:igfitidea点击:

AndroidDriver cannot be resolved to a type

javaandroidseleniumbrowser-automation

提问by kk1076

I am new to java. I am trying to create a sample mobile automation testing application using Selenium web driver for android.
I have installed the Android SDK and started the Android emulator based on the guidelines from the below links.
http://www.abodeqa.com/2013/05/08/configuring-android-webdriver-in-eclipse/
http://selenium.polteq.com/en/running-tests-on-an-android-simulator/
https://code.google.com/p/selenium/wiki/AndroidDriver

我是 Java 新手。我正在尝试使用适用于 android 的 Selenium Web 驱动程序创建一个示例移动自动化测试应用程序。
我已经安装了 Android SDK 并根据以下链接中的指南启动了 Android 模拟器。
http://www.abodeqa.com/2013/05/08/configuring-android-webdriver-in-eclipse/
http://selenium.polteq.com/en/running-tests-on-an-android-simulator/
https://code.google.com/p/selenium/wiki/AndroidDriver

I added the external jar files for selenium (selenium-server-standalone-2.42.2) and started the emulator using apk (android-server-2.38.0.apk) and added the code from the links.

我为 selenium ( selenium-server-standalone-2.42.2)添加了外部 jar 文件,并使用 apk ( android-server-2.38.0.apk)启动了模拟器,并添加了来自链接的代码。

I get reference errors for android driver as (The import.org.selenium.android cannot be resolved)

我收到 Android 驱动程序的参考错误为 ( The import.org.selenium.android cannot be resolved)

import org.openqa.selenium.android.AndroidDriver;

and in the below code as (Android driver cannot be resolved to a type)

并在下面的代码中(Android驱动程序无法解析为类型

AndroidDriver driver = new AndroidDriver();

How to solve these reference errors for android ?.
Any suggestions will be greatly helpful. Thanks in advance.

如何解决android的这些参考错误?。
任何建议都会非常有帮助。提前致谢。

EDIT : Added Screenshot Screenshot android reference error

编辑:添加屏幕截图 截图android参考错误

回答by SahilPatel

I think so android driver is belongs to java-client library so giving an error that android driver cannot resolve as type. please add java-client library and then import android driver that can solve problem. this link can help you with java-client :-http://mvnrepository.com/artifact/io.appium/java-clientand then user import statement in eclipse :- import io.appium.java_client.android.AndroidDriver; Try this it may help you

我认为 android 驱动程序属于 java-client 库,因此给出了 android 驱动程序无法解析为类型的错误。请添加java客户端库,然后导入可以解决问题的android驱动程序。此链接可以帮助您使用 java-client :- http://mvnrepository.com/artifact/io.appium/java-client然后在 eclipse 中使用用户导入语句:- import io.appium.java_client.android.AndroidDriver; 试试这个它可能会帮助你

回答by Nandini

I had faced same problem in Windows 7 64-bit.

我在 64 位 Windows 7 中遇到了同样的问题。

Doing below steps my error got solved:-

执行以下步骤,我的错误得到解决:-

  • Downloaded Java-client jar from https://mvnrepository.com/artifact/io.appium/java-client/2.1.0.

  • Add the Jar to Build Path of my project. [Right click >>> Build Path >>> Configure build path >>> Libraries tab >>> Add external jars >>> Now select your downloaded java-client].

  • Now in your class add import as :import io.appium.java_client.android.AndroidDriver;

  • Save the class.

  • https://mvnrepository.com/artifact/io.appium/java-client/2.1.0下载 Java 客户端 jar 。

  • 将 Jar 添加到我的项目的构建路径。[右键单击 >>> 构建路径 >>> 配置构建路径 >>> 库选项卡 >>> 添加外部 jar >>> 现在选择您下载的 java 客户端]。

  • 现在在你的类中添加 import as :import io.appium.java_client.android.AndroidDriver;

  • 保存课程。

After following above steps i am successfully able to access Android drivers.

按照上述步骤操作后,我可以成功访问 Android 驱动程序。

回答by Nandini

In case you are running a maven java project, add the following dependency to your POM and that should add the java-client jars to your project automatically. Once added, the error should go away.

如果您正在运行 maven java 项目,请将以下依赖项添加到您的 POM,这应该会自动将 java-client jar 添加到您的项目中。添加后,错误应该消失。

<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>5.0.2</version>
</dependency>