2010-08-17 21 views
8

he descargado el selenium-java-2.0a5.zipjava.lang.ClassNotFoundException: API WebDriver

http://code.google.com/p/selenium/downloads/list

y corrió el siguiente código:

package org.openqa.selenium.example; 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.htmlunit.HtmlUnitDriver; 

public class Example { 
    public static void main(String[] args) { 
     // Create a new instance of the html unit driver 
     // Notice that the remainder of the code relies on the interface, 
     // not the implementation. 
     WebDriver driver = new HtmlUnitDriver(); 

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

pero luego me

at org.openqa.selenium.example.Example.main(Example.java:13) 
Caused by: java.lang.ClassNotFoundException: com.gargoylesoftware.htmlunit.WebWindowListener 
    at java.net.URLClassLoader$1.run(Unknown Source) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) 
    at java.lang.ClassLoader.loadClass(Unknown Source) 
    ... 1 more 

¿Echo de menos un paso? Me aseguré de importar el selenium-java-2.0a5.jar en el proyecto.

+0

mira mi respuesta. olvidaste agregar el jar de HtmlUnit al classpath. – YoK

Respuesta

10

htmlunit jar no está en el classpath. Incluye jar de lib de dependencia de selenio-java-2.0a5.jar también. Estoy seguro de que se deben haber proporcionado en el zip que descargó

2

Parece que usa "HtmlUnit" en su proyecto y su jar falta en classpath. Agréguelo a las propiedades de su proyecto cuando agregue selenio.

Cuestiones relacionadas