cuốn sách gpt4 ai đã làm

java - WebDriver 和 ChromeDriver : Unable to fix org/json/JSONException error

In lại Tác giả: Vũ trụ không gian 更新时间:2023-11-04 09:55:50 25 4
mua khóa gpt4 Nike

我刚开始使用 Selenium WebDriver。我正在尝试使用 ChromeDriver,以下是我的代码:

public class WebScraper {
public WebScraper() {

}

public WebDriver driver = new ChromeDriver();

public void openTestSite() {
driver.navigate().to("https://google.com");
}


public void enter(String word) {

WebElement query_editbox =
driver.findElement(By.id("query"));
query_editbox.sendKeys(word);
query_editbox.sendKeys(Keys.RETURN);

}

// public void getText() {
// //List searchResults =
// driver.findElements(By.xpath("//div[@id='mid']/div"));
// // Writer writer = new BufferedWriter(new
// OutputStreamWriter(new FileOutputStream("status.txt"),
// "utf-8"));
// //int[] index = {0};
//
// WebElement result=driver.findElement(By.id("mid"));
// System.out.println(result.getText());
//}

public static void main(String[] args) ném IOException {
System.setProperty("webdriver.chrome.driver", "chromedriver");
System.out.println("Hello");

WebScraper webScraper = new WebScraper();
webSrcapper.openTestSite();
webSrcapper.enter("avoir");
//webSrcapper.getText();
System.out.println("Hello");

}
}

Tôi nhận được lỗi sau:

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONException
at org.openqa.selenium.remote.RemoteWebDriver.init(RemoteWebDriver.java:110)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:92)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:144)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:86)
at WebScraper.(WebScraper.java:15)
at WebScraper.main(WebScraper.java:47)
Caused by: java.lang.ClassNotFoundException: org.json.JSONException
tại java.net.URLClassLoader.findClass(URLClassLoader.java:381)
tại java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
tại java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 nữa

有人可以帮我解决这个问题并告诉我为什么我首先会收到此错误吗?

Cảm ơn!

câu trả lời hay nhất

sai lầm

Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONException

是因为它缺少依赖org.jsonthêm cái nàyhttps://mvnrepository.com/artifact/org.json/json/20180813

关于java - WebDriver 和 ChromeDriver : Unable to fix org/json/JSONException error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54172871/

25 4 0
không gian vũ trụ
Hồ sơ

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá taxi Didi miễn phí
Phiếu giảm giá taxi Didi
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress