【问题标题】:getting exception while execution of selenium web driver program执行 selenium web 驱动程序时出现异常
【发布时间】:2014-09-25 09:39:59
【问题描述】:

我正在执行简单的 java 程序并尝试执行我的第一个 selenium 脚本。

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

        driver.quit();
    }

这些是我添加的依赖项:

但是在运行这段代码之后,我在 eclipse 中遇到了这个异常。

java.lang.ClassNotFoundException: org.apache.xerces.xni.XNIException

【问题讨论】:

  • 为什么你有 xerces.jar ,我认为不需要运行 selenium 脚本。删除它,然后再试一次。

标签: eclipse testing selenium selenium-webdriver


【解决方案1】:

ClassNotFoundException 主要发生在在指定的类路径中找不到类文件时。因此,请尝试删除 xerces.jar 并重新添加。

【讨论】:

  • 我之前在没有 xerces.jar 的情况下这样做,但它抛出了我提到的异常。所以我添加了这个罐子。现在我再次删除了罐子,但得到了同样的异常。 :(
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-11-27
  • 2014-11-05
  • 2018-01-13
  • 2017-09-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多