java - 如何解决这个 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)
我在用:
- 火狐 - 47.0.1
- 硒驱动程序 - 2.53.1
- htmlunit 驱动程序 - 2.30.1
如果我更新 firefox,那么我不能使用 firepath 和 firebug。 如果我更新 selenium 驱动程序,那么我必须更新 firefox。
解决方案
推荐阅读
- android-studio - 注释Android Room Dao的正确方法?
- asp.net-core-webapi - .Net Core Web API - 如何填充包含通用列表的 DTO
- angular - 刷新 Angular 10 ESRI 地图上的图层而不刷新整个地图
- javascript - 我有一个带有签名的文件,如何验证内容与客户端上的签名+公钥匹配?
- android - 提供程序不在另一个屏幕中显示更新状态,而仅在模态类和更改通知程序所在的第一个屏幕上显示
- graphics - Gnuplot:如何在多个数据块上用连续线绘制?
- java - 编译依赖版本和运行时依赖版本可以不同吗?
- css - 如何使用 CSS 以一行而不是两行呈现图像?
- android - 如何创建一个可以360度循环的Recylerview?
- reactjs - 如何使用 React Navigation v5 在 React Native 中获取当前路由名称