【问题标题】:How to compile a java application which uses Google webdriver from comand line without ant [duplicate]如何在没有任何 [重复] 的情况下从命令行编译使用 Google webdriver 的 Java 应用程序
【发布时间】:2008-09-16 13:32:39
【问题描述】:

我想编译一个使用 google 的 webdriver 的示例代码。

我将 webdriver 保存到 /home/iyo/webdriver。我的代码是:

包 com.googlecode.webdriver.example; 导入 com.googlecode.webdriver.By; 导入 com.googlecode.webdriver.WebDriver; 导入 com.googlecode.webdriver.WebElement; 导入 com.googlecode.webdriver.htmlunit.HtmlUnitDriver; 公共类 FirstTest { 公共静态无效主要(字符串[]参数){ WebDriver driver = new HtmlUnitDriver(); driver.get("http://www.google.com"); WebElement 元素 = driver.findElement(By.xpath("//input[@name = 'q']")); element.sendKeys("奶酪!"); 元素.提交(); System.out.println("页面标题为:" + driver.getTitle()); } }

但我跟

javac -cp /home/iyo/webdriver FirstTest.java
我得到这样的错误:
FirstTest.java:5: 找不到符号

符号:类依据

位置:com.googlecode.webdriver 包

导入 com.googlecode.webdriver.By;

                           ^

FirstTest.java:7: 找不到符号

符号:类 WebDriver

位置:com.googlecode.webdriver 包

导入 com.googlecode.webdriver.WebDriver;

                           ^

FirstTest.java:9: 找不到符号

符号:类 WebElement

位置:com.googlecode.webdriver 包

导入 com.googlecode.webdriver.WebElement;

                           ^

FirstTest.java:11:com.googlecode.webdriver.htmlunit 包不存在

导入 com.googlecode.webdriver.htmlunit.HtmlUnitDriver;

                                    ^

FirstTest.java:19: 找不到符号

符号:类 WebDriver

位置:com.googlecode.webdriver.example.FirstTest 类

    WebDriver driver = new HtmlUnitDriver();        

    ^

FirstTest.java:19: 找不到符号

符号:类 HtmlUnitDriver

位置:com.googlecode.webdriver.example.FirstTest 类

    WebDriver driver = new HtmlUnitDriver();        

                           ^

FirstTest.java:27: 找不到符号

符号:类 WebElement

位置:com.googlecode.webdriver.example.FirstTest 类

    WebElement element =

    ^

FirstTest.java:29: 找不到符号

符号:变量由

位置:com.googlecode.webdriver.example.FirstTest 类

    driver.findElement(By.xpath("//input[@name = 'q']"));

                       ^

8 个错误

Its possible to use it whitouht Ant?(The code in NetBeans or Eclipse work well, but I dont 想使用它们。)仅使用 javac?

谢谢。

【问题讨论】:

    标签: java ant compiler-construction webdriver


    【解决方案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后面

    javac -cp /home/iyo/webdriver/common/build/webdriver-common.jar:/home/iyo/webdriver/common/build/webdriver-htmlunit.jar FirstTest.java
    

    您可能还必须将 htmlunit/lib/runtime 中的所有 jar 文件添加到类路径中。

    【讨论】:

    • 我完全用你的参数运行它(+我从 $WEBDRIVER_HOME/htmlunit/lib/runtime 添加 JAR),但它仍然有同样的问题。
    • 也许你把你最终执行的完整行贴出来,然后我们就可以看到问题所在了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-17
    • 1970-01-01
    • 1970-01-01
    • 2016-09-10
    相关资源
    最近更新 更多