作者:额哦哦额llo | 来源:互联网 | 2023-10-11 11:57
IamstartedwritingscriptonHtmlUnitDriverbutgotsomeerror.Iamgettingerrorjava.lang.NoCl
I am started writing script on HtmlUnitDriver but got some error. I am getting error "java.lang.NoClassDefFoundError". Please help me out. Check the code and error in detail below.
我开始在HtmlUnitDriver上编写脚本但是出了点错误。我收到错误“java.lang.NoClassDefFoundError”。请帮帮我。请在下面详细检查代码和错误。
Here is the Code:
这是代码:
package com.pom.sampletests;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class HtmlUnitYest {
public static void main(String[] args) throws Exception {
// Creating a new instance of the HTML unit driver
WebDriver driver = new HtmlUnitDriver();
Thread.sleep(2000L);
// Navigate to Google
driver.get("http://www.google.com");
// Locate the searchbox using its name
WebElement element = driver.findElement(By.name("q"));
// Enter a search query
element.sendKeys("Guru99");
// Submit the query. Webdriver searches for the form using the text input element automatically
// No need to locate/find the submit button
element.submit();
// This code will print the page title
System.out.println("Page title is: " + driver.getTitle());
driver.quit();
}
}
Here is the error:
这是错误:
Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/remote/SessionNotFoundException
at com.pom.sampletests.HtmlUnitYest.main(HtmlUnitYest.java:11)
Caused by: java.lang.ClassNotFoundException: org.openqa.selenium.remote.SessionNotFoundException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
POM:
4.0.0
TestNGPro
TestNGPro
0.0.1-SNAPSHOT
CBA Automation
TestNGPro
org.seleniumhq.selenium
selenium-java
${selenium.version}
org.testng
testng
6.10
org.seleniumhq.selenium
selenium-htmlunit-driver
2.52.0
1.6
3.1.0
Any suggestions might helpful.
任何建议都可能有用。
2 个解决方案