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

时间:2013-07-02 09:42:51

标签: java android eclipse selenium-webdriver adt

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

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

我已从上述网站复制以下代码,如下所示:

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();
  }
}

但在以下行找到了“WebDriver无法解析为某种类型”的错误:

WebDriver driver = new AndroidDriver();

WebDriver cannot be resolved to a type

注意:我已将“selenium-server-standalone-2.33.0.jar”添加到Java Build Path

3 个答案:

答案 0 :(得分:1)

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

import org.openqa.selenium.WebDriver;

答案 1 :(得分:0)

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

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

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

答案 2 :(得分:0)

添加 - 导入org.openqa.selenium.WebElement;

相关问题