eclipse Android WebDriver java 代码中的“WebDriver 无法解析为类型”错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17422296/
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-09-19 20:50:00  来源:igfitidea点击:

"WebDriver cannot be resolved to a type" error in Android WebDriver java code

javaandroideclipseselenium-webdriveradt

提问by Ripon Al Wasim

I have prepared the environment for test automation of Android Application using eclipse. I have followed the instruction from the below site:

我已经准备好了使用eclipse进行Android应用程序自动化测试的环境。我已按照以下网站的说明进行操作:

https://code.google.com/p/selenium/wiki/AndroidDriver#Setup_the_Environment

I have copied the following code from the above website as below:

我从上面的网站复制了以下代码,如下所示:

import junit.framework.TestCase;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.android.AndroidDriver;

public class OneTest extends TestCase {

  public void testGoogle() throws Exception {
    WebDriver driver = new AndroidDriver();

    // And now use this to visit Google
    driver.get("http://www.google.com");

    // Find the text input element by its name
    WebElement element = driver.findElement(By.name("q"));

    // Enter something to search for
    element.sendKeys("Cheese!");

    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());
    driver.quit();
  }
}

But error as "WebDriver cannot be resolved to a type" was found at the following line:

但是在以下行中发现了“WebDriver 无法解析为类型”的错误:

WebDriver driver = new AndroidDriver();

WebDriver cannot be resolved to a type

WebDriver 无法解析为类型

Note: I have added "selenium-server-standalone-2.33.0.jar" to Java Build Path

注意:我在 Java Build Path 中添加了“selenium-server-standalone-2.33.0.jar”

回答by Ripon Al Wasim

Only one import statement is needed to fix the error. import the following and that's it:

只需要一个导入语句来修复错误。导入以下内容,就是这样:

import org.openqa.selenium.WebDriver;

回答by Dipak Tivarekar

Add - import org.openqa.selenium.WebElement;

添加 - 导入 o​​rg.openqa.selenium.WebElement;

回答by pundit

You need to properly install the android server available here http://code.google.com/p/selenium/downloads/list.

您需要正确安装http://code.google.com/p/selenium/downloads/list此处提供的 android 服务器。

Follow this tutorial http://code.google.com/p/selenium/wiki/AndroidDriver#Install_the_Android_SDK

按照本教程http://code.google.com/p/selenium/wiki/AndroidDriver#Install_the_Android_SDK

regarding how to install the android web driver.

关于如何安装 android 网络驱动程序。