我想编译一个使用google`s webdriver的示例代码 .
我将webdriver保存到/ home / iyo / webdriver中 . 我的代码是:
package com.googlecode.webdriver.example;
import com.googlecode.webdriver.By;
import com.googlecode.webdriver.WebDriver;
import com.googlecode.webdriver.WebElement;
import com.googlecode.webdriver.htmlunit.HtmlUnitDriver;
public class FirstTest {
public static void main(String[] args) {
WebDriver driver = new HtmlUnitDriver();
driver.get("http://www.google.com");
WebElement element =
driver.findElement(By.xpath("//input[@name = 'q']"));
element.sendKeys("Cheese!");
element.submit();
System.out.println("Page title is: " + driver.getTitle());
}
}
但我跟
javac -cp /home/iyo/webdriver FirstTest.java
我收到这样的错误:
FirstTest.java:5: cannot find symbol
symbol : class By
location: package com.googlecode.webdriver
import com.googlecode.webdriver.By;
^
FirstTest.java:7: cannot find symbol
symbol : class WebDriver
location: package com.googlecode.webdriver
import com.googlecode.webdriver.WebDriver;
^
FirstTest.java:9: cannot find symbol
symbol : class WebElement
location: package com.googlecode.webdriver
import com.googlecode.webdriver.WebElement;
^
FirstTest.java:11: package com.googlecode.webdriver.htmlunit does not exist
import com.googlecode.webdriver.htmlunit.HtmlUnitDriver;
^
FirstTest.java:19: cannot find symbol
symbol : class WebDriver
location: class com.googlecode.webdriver.example.FirstTest
WebDriver driver = new HtmlUnitDriver();
^
FirstTest.java:19: cannot find symbol
symbol : class HtmlUnitDriver
location: class com.googlecode.webdriver.example.FirstTest
WebDriver driver = new HtmlUnitDriver();
^
FirstTest.java:27: cannot find symbol
symbol : class WebElement
location: class com.googlecode.webdriver.example.FirstTest
WebElement element =
^
FirstTest.java:29: cannot find symbol
symbol : variable By
location: class com.googlecode.webdriver.example.FirstTest
driver.findElement(By.xpath("//input[@name = 'q']"));
^
8 errors
它 s possible to use it whitouht Ant?(The code in NetBeans or Eclipse work well, but I don
t想要使用它们 . )只有javac?
谢谢 .
1 回答
在webdriver homepage上可以阅读
将$ WEBDRIVER_HOME / common / build / webdriver-common.jar添加到CLASSPATH
将$ WEBDRIVER_HOME / htmlunit / build / webdriver-htmlunit.jar添加到CLASSPATH
将$ WEBDRIVER_HOME / htmlunit / lib / runtime下的所有Jar文件添加到CLASSPATH
所以你必须将所有jar文件放在
-cp
后面您可能还必须将htmlunit / lib / runtime中的所有jar文件添加到类路径中 .