2013-07-02 70 views
2

我已经准备好了使用eclipse进行Android应用程序测试自动化的环境。我按照从下面的网站上的说明:“WebDriver无法解析为类型”错误Android WebDriver java代码

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构建路径

+0

你是否在该链接的代码之后立即遵循构造?它说你需要包括一些外部的罐子 – Neoh

+0

我已经添加了所需的外部罐子 –

回答

0

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

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

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

+0

感谢评论家为您的答案。但安装时没有问题。我已经正确并成功地安装了“android-server-2.32.0.apk”。这是代码中的编译错误。 –

+0

嗨,我已经通过maven实际完成了它。所以不是很确定的解决方案,但你可以请将硒-java-2.33.0.jar文件添加到内置路径 – pundit

+0

我已经添加了selenium-java-2.33.0.jar。但不幸的是没有任何帮助 –

1

只需要一条导入语句来修复错误。导入以下内容即可:

import org.openqa.selenium.WebDriver; 
0

Add - import org.openqa.selenium.WebElement;

相关问题