-3

I want to compile an example code which using google`s webdriver.

I saved webdriver into /home/iyo/webdriver. My code is:

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

    }

}

But I with

javac -cp /home/iyo/webdriver FirstTest.java
I got errors like this:
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

Its possible to use it whitouht Ant?(The code in NetBeans or Eclipse work well, but I dont want to use them.) Only with javac?

Thanks.

Charles
  • 50,943
  • 13
  • 104
  • 142

1 Answers1

1

On the webdriver homepage one can read

  • Add $WEBDRIVER_HOME/common/build/webdriver-common.jar to the CLASSPATH
  • Add $WEBDRIVER_HOME/htmlunit/build/webdriver-htmlunit.jar to the CLASSPATH
  • Add all the Jar files under $WEBDRIVER_HOME/htmlunit/lib/runtime to the CLASSPATH

So you have to put all the jar files behind -cp like that

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

You probably have to add all the jar files from htmlunit/lib/runtime to the classpath as well.

jrudolph
  • 8,307
  • 4
  • 32
  • 50
  • I run it exactly with your parameters (+I add JAR from $WEBDRIVER_HOME/htmlunit/lib/runtime) but it has got still same problems. –  Sep 16 '08 at 17:43
  • Perhaps you post the complete line you finally executed then we can see what the problem is. – jrudolph Sep 17 '08 at 07:53