0

我试图从一个动态 Web 项目中实现一个 Web 服务。我将 selenium-server-standalone-2.32.0.jar 文件添加到构建路径中,然后我还将它添加到 WEB-INF/lib 文件夹中。然后我使用 Web 服务向导从项目中生成 Web 服务。在向导开始时,它显示了一个弹出警告,内容如下:

The service class "test.eko3.TestEko3" does not comply to one or more requirements of the JAX-RPC 1.1 specification, and may not deploy or function correctly.
The value type "org.openqa.selenium.WebDriver" used via the service class "test.eko3.TestEko3" does not have a public default constructor. Chapter 5.4 of the JAX-RPC 1.1 specification requires a value type to have a public default constructor, otherwise a JAX-RPC 1.1 compliant Web service engine may be unable to construct an instance of the value type during deserialization.
The field or property "windowHandles" on the value type "org.openqa.selenium.WebDriver" used via the service class "test.eko3.TestEko3" has a data type, "java.util.Set", that is not supported by the JAX-RPC 1.1 specification. Instances of the type may not serialize or deserialize correctly. Loss of data or complete failure of the Web service may result.

我单击确定,它生成了 Web 服务器和客户端,并在 Eclipse 的浏览器中显示了客户端。但是当我输入参数并单击调用时,它会在结果部分显示此异常:

Exception: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver; nested exception is: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver Message: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver; nested exception is: java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver 

由于我将 selenium jar 添加到 buildpath 和 WEB-INF/lib 文件夹中,我不确定它为什么找不到该类。服务器的代码如下:

package test.eko3;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;

public class TestEko3 {
public String Ekobilet(String from, String to, String date) {

    //Firefox browser instantiation
    WebDriver driver = new FirefoxDriver();

    //Loading the URL
    driver.get("http://www.amadeusepower.com/trek/portals/trek/default.aspx?Culture=en-US");


    WebElement radioOneway = driver.findElement(By.id("ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_rbFlightType_1"));
    radioOneway.click();

    waitForPageLoaded(driver);


    WebElement fromText = driver.findElement(By.id("ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_txtSearch_txtFrom"));
    fromText.clear();
    fromText.sendKeys(from); 


    WebElement toText = driver.findElement(By.id("ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_txtSearch_txtTo"));
    toText.sendKeys(to); 


    WebElement dateText = driver.findElement(By.id("ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_txtDepartureDate_txtDate"));
    dateText.sendKeys(date); 

    //Sign in button identification and click it
    WebElement searchbutton = driver.findElement(By.id("ctl00_ctl00_ctl00_cph1_cph1_QuickSearchAll1_QuickFlightSearchControl1_btnSearch"));
    searchbutton.click();

    String page = driver.getPageSource();

//      Writer out = new BufferedWriter(new OutputStreamWriter(
//                  new FileOutputStream("ekobiletselenium.html"), "UTF-8"));
//              try {
//                  out.write(page);
//              } finally {
//                  out.close();
//              }
    //Closing the browser
    driver.close();

    return page;

    }

    public static void waitForPageLoaded(WebDriver driver) {

        ExpectedCondition<Boolean> expectation = new
    ExpectedCondition<Boolean>() {
           public Boolean apply(WebDriver driver) {
             return ((JavascriptExecutor)driver).executeScript("return document.readyState").equals("complete");
           }
         };

        Wait<WebDriver> wait = new WebDriverWait(driver,30);
         try {
                 wait.until(expectation);
         } catch(Throwable error) {
                 System.out.println("exception yavrum");
         }
    } 

}

有人可以告诉我这是什么原因吗?我是否缺少硒依赖的 jar 文件?任何帮助,将不胜感激。

4

3 回答 3

0

当项目中没有完全引用 selenium 时,会出现此异常。

以下是您可以采取的解决问题的步骤:

  1. 在此处下载 Selenium 客户端和 WebDriver Java 绑定。
  2. 解压下载的文件。
  3. 将主要的 selenium '.jar'(例如:)复制selenium-java-2.42.2.jar到 Web 项目的WebContent/WEB-INF/lib目录中。
  4. 还将 Unzipped selenium libs 目录中的所有文件复制到 Web 项目的目录中。.jarWebContent/WEB-INF/lib

您现在应该能够运行代码而不会出现java.lang.NoClassDefFoundError: org/openqa/selenium/WebDriver异常。

于 2014-09-14T19:21:26.963 回答
0

请检查此链接绝对可以得到@thedrs回答的想法

http://me-ol-blog.blogspot.co.il/2013/07/using-selenium-in-java-dynamic-web.html

于 2015-01-28T13:14:11.153 回答
0

也许您正在使用不适合 Web 项目的独立 jar。见http://me-ol-blog.blogspot.co.il/2013/07/using-selenium-in-java-dynamic-web.html

于 2013-07-22T16:17:34.330 回答