首页 > 解决方案 > 如何解决这个 java.lang.NoSuchFieldError: DISMISS_AND_NOTIFY?

问题描述

我正在尝试执行下面的代码,但我得到了这个异常。代码似乎没问题,我也检查了其他东西,但它显示了相同的异常。

我的代码:

import java.util.concurrent.TimeUnit;

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



public class Prog29 {

    public static void main(String[] args) throws InterruptedException
    {
        WebDriver unitDriver= new HtmlUnitDriver(); 
        unitDriver.manage().timeouts().implicitlyWait(150, TimeUnit.SECONDS);

        unitDriver.get("http://google.com");

        System.out.println("title of the page is :"+unitDriver.getTitle());

        WebElement element = unitDriver.findElement(By.xpath(".//*[@id='gs_htif0']"));
        element.sendKeys("Selenium");

        unitDriver.findElement(By.xpath(".//*[@id='tsf']/div[2]/div[3]/center/input[1]")).click();

        Thread.sleep(10000);
        System.out.println("title of the page is :"+unitDriver.getTitle());
        unitDriver.close();

    }

}

我得到的例外:

Exception in thread "main" java.lang.NoSuchFieldError: DISMISS_AND_NOTIFY
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:225)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:211)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:201)
    at org.openqa.selenium.htmlunit.HtmlUnitDriver.<init>(HtmlUnitDriver.java:191)
    at level1.Prog29.main(Prog29.java:16)

我在用:

  1. 火狐 - 47.0.1
  2. 硒驱动程序 - 2.53.1
  3. htmlunit 驱动程序 - 2.30.1

如果我更新 firefox,那么我不能使用 firepath 和 firebug。 如果我更新 selenium 驱动程序,那么我必须更新 firefox。

标签: javaselenium

解决方案


推荐阅读