I am encountering an error when I run my class file.
Here is the error message:
Task :compileJava UP-TO-DATE
Task :processResources UP-TO-DATE
Task :classes UP-TO-DATE
Task :CrawlingTest.main() FAILED
3 actionable tasks: 1 executed, 2 up-to-date
Exception in thread “main” java.lang.AbstractMethodError: Receiver class org.openqa.selenium.chrome.ChromeDriverService$Builder does not define or inherit an implementation of the resolved method ‘abstract java.io.File findDefaultExecutable()’ of abstract class org.openqa.selenium.remote.service.DriverService$Builder.
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:437)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:138)
at org.openqa.selenium.chrome.ChromeDriver.(ChromeDriver.java:72)
at Nawa3.Nawa3.service.CrawlingTest.getChromeDriver(CrawlingTest.java:40)
at Nawa3.Nawa3.service.CrawlingTest.main(CrawlingTest.java:47)
FAILURE: Build failed with an exception.
- What went wrong:
Execution failed for task ‘:CrawlingTest.main()’.
Process ‘command ‘C:/Users/ASUS/.jdks/openjdk-17.0.2/bin/java.exe” finished with non-zero exit value 1
Run with –stacktrace option to get the stack trace.
Run with –info or –debug option to get more log output.
Run with –scan to get full insights.
- Get more help at https://help.gradle.org
BUILD FAILED in 1s
I’ve seen an article about the dependency issue and tried the suggested fixes, but the problem persists.
Class File
Here is the class file I am using:
<code>package Nawa3.Nawa3.service;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.time.Duration;
import java.util.ArrayList;
public class CrawlingTest {
private static WebDriver driver;
public static String WEB_DRIVER_ID = "webdriver.chrome.driver";
private static String WEB_DRIVER_PATH = "C:\Users\ASUS\Downloads\chromedriver-win64\chromedriver-win64\chromedriver.exe";
public static WebDriver getChromeDriver() {
if (System.getProperty("webdriver.chrome.driver") == null) {
System.setProperty("webdriver.chrome.driver", WEB_DRIVER_PATH);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--remote-allow-origins=*");
chromeOptions.addArguments("--disable-web-security");
chromeOptions.addArguments("--disable-gpu");
chromeOptions.addArguments("--no-sandbox");
chromeOptions.addArguments("--disable-dev-shm-usage");
chromeOptions.addArguments("--disable-blink-features=AutomationControlled");
chromeOptions.addArguments("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36");
chromeOptions.addArguments("Accept-Language=ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7");
chromeOptions.addArguments("Accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(30));
public static void main(String[] args) {
WebDriver driver = getChromeDriver();
String url = "https://map.naver.com/p/search/%ED%99%8D%EB%8C%80%EC%9E%85%EA%B5%AC%EC%97%AD%EB%A7%9B%EC%A7%91?c=16.24,0,0,0,dh";
List<WebElement> webElementList = new ArrayList<>();
String query = "span.place_bluelink.TYaxT";
String iframeId = "searchIframe";
driver.switchTo().frame(driver.findElement(By.id(iframeId)));
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
webElementList = driver.findElements(By.cssSelector(query));
for (WebElement element : webElementList) {
System.out.println(element.getText());
driver.switchTo().defaultContent();
System.out.println("Page title is: " + driver.getTitle());
System.out.println("Current URL: " + driver.getCurrentUrl());
System.out.println("An error occurred: " + e.getMessage());
<code>package Nawa3.Nawa3.service;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
public class CrawlingTest {
private static WebDriver driver;
public static String WEB_DRIVER_ID = "webdriver.chrome.driver";
private static String WEB_DRIVER_PATH = "C:\Users\ASUS\Downloads\chromedriver-win64\chromedriver-win64\chromedriver.exe";
public static WebDriver getChromeDriver() {
if (System.getProperty("webdriver.chrome.driver") == null) {
System.setProperty("webdriver.chrome.driver", WEB_DRIVER_PATH);
}
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--remote-allow-origins=*");
chromeOptions.addArguments("--disable-web-security");
chromeOptions.addArguments("--disable-gpu");
chromeOptions.addArguments("--no-sandbox");
chromeOptions.addArguments("--disable-dev-shm-usage");
chromeOptions.addArguments("--disable-blink-features=AutomationControlled");
chromeOptions.addArguments("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36");
chromeOptions.addArguments("Accept-Language=ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7");
chromeOptions.addArguments("Accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(30));
return driver;
}
public static void main(String[] args) {
WebDriver driver = getChromeDriver();
String url = "https://map.naver.com/p/search/%ED%99%8D%EB%8C%80%EC%9E%85%EA%B5%AC%EC%97%AD%EB%A7%9B%EC%A7%91?c=16.24,0,0,0,dh";
List<WebElement> webElementList = new ArrayList<>();
String query = "span.place_bluelink.TYaxT";
String iframeId = "searchIframe";
try {
driver.get(url);
Thread.sleep(5000);
driver.switchTo().frame(driver.findElement(By.id(iframeId)));
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
webElementList = driver.findElements(By.cssSelector(query));
for (WebElement element : webElementList) {
System.out.println(element.getText());
}
driver.switchTo().defaultContent();
System.out.println("Page title is: " + driver.getTitle());
System.out.println("Current URL: " + driver.getCurrentUrl());
} catch (Exception e) {
System.out.println("An error occurred: " + e.getMessage());
} finally {
driver.quit();
}
}
}
</code>
package Nawa3.Nawa3.service;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
public class CrawlingTest {
private static WebDriver driver;
public static String WEB_DRIVER_ID = "webdriver.chrome.driver";
private static String WEB_DRIVER_PATH = "C:\Users\ASUS\Downloads\chromedriver-win64\chromedriver-win64\chromedriver.exe";
public static WebDriver getChromeDriver() {
if (System.getProperty("webdriver.chrome.driver") == null) {
System.setProperty("webdriver.chrome.driver", WEB_DRIVER_PATH);
}
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--remote-allow-origins=*");
chromeOptions.addArguments("--disable-web-security");
chromeOptions.addArguments("--disable-gpu");
chromeOptions.addArguments("--no-sandbox");
chromeOptions.addArguments("--disable-dev-shm-usage");
chromeOptions.addArguments("--disable-blink-features=AutomationControlled");
chromeOptions.addArguments("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36");
chromeOptions.addArguments("Accept-Language=ko-KR,ko;q=0.9,en-US;q=0.8,en;q=0.7");
chromeOptions.addArguments("Accept=text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(30));
return driver;
}
public static void main(String[] args) {
WebDriver driver = getChromeDriver();
String url = "https://map.naver.com/p/search/%ED%99%8D%EB%8C%80%EC%9E%85%EA%B5%AC%EC%97%AD%EB%A7%9B%EC%A7%91?c=16.24,0,0,0,dh";
List<WebElement> webElementList = new ArrayList<>();
String query = "span.place_bluelink.TYaxT";
String iframeId = "searchIframe";
try {
driver.get(url);
Thread.sleep(5000);
driver.switchTo().frame(driver.findElement(By.id(iframeId)));
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
webElementList = driver.findElements(By.cssSelector(query));
for (WebElement element : webElementList) {
System.out.println(element.getText());
}
driver.switchTo().defaultContent();
System.out.println("Page title is: " + driver.getTitle());
System.out.println("Current URL: " + driver.getCurrentUrl());
} catch (Exception e) {
System.out.println("An error occurred: " + e.getMessage());
} finally {
driver.quit();
}
}
}
build.gradle
This is my build.gradle file:
id 'org.springframework.boot' version '3.0.2'
id 'io.spring.dependency-management' version '1.1.0'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
extendsFrom annotationProcessor
implementation 'org.seleniumhq.selenium:selenium-java:4.21.0'
implementation 'org.seleniumhq.selenium:selenium-chrome-driver:4.21.0'
implementation 'org.mariadb.jdbc:mariadb-java-client:3.0.10'
implementation('org.modelmapper:modelmapper:2.4.2')
developmentOnly("org.springframework.boot:spring-boot-devtools")
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation group: 'org.jsoup', name: 'jsoup', version: '1.15.3'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
testImplementation 'org.mockito:mockito-core:3.6.0'
testImplementation 'org.mockito:mockito-junit-jupiter:3.6.0'
<code>plugins {
id 'java'
id 'org.springframework.boot' version '3.0.2'
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'Nawa3'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
// Selenium dependency
implementation 'org.seleniumhq.selenium:selenium-java:4.21.0'
implementation 'org.seleniumhq.selenium:selenium-chrome-driver:4.21.0'
// MariaDB dependency
implementation 'org.mariadb.jdbc:mariadb-java-client:3.0.10'
implementation('org.modelmapper:modelmapper:2.4.2')
developmentOnly("org.springframework.boot:spring-boot-devtools")
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation group: 'org.jsoup', name: 'jsoup', version: '1.15.3'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// JPA dependency
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
testImplementation 'org.mockito:mockito-core:3.6.0'
testImplementation 'org.mockito:mockito-junit-jupiter:3.6.0'
}
tasks.named('test') {
useJUnitPlatform()
}
</code>
plugins {
id 'java'
id 'org.springframework.boot' version '3.0.2'
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'Nawa3'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
// Selenium dependency
implementation 'org.seleniumhq.selenium:selenium-java:4.21.0'
implementation 'org.seleniumhq.selenium:selenium-chrome-driver:4.21.0'
// MariaDB dependency
implementation 'org.mariadb.jdbc:mariadb-java-client:3.0.10'
implementation('org.modelmapper:modelmapper:2.4.2')
developmentOnly("org.springframework.boot:spring-boot-devtools")
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.mysql:mysql-connector-j'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation group: 'org.jsoup', name: 'jsoup', version: '1.15.3'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
// JPA dependency
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
testImplementation 'org.mockito:mockito-core:3.6.0'
testImplementation 'org.mockito:mockito-junit-jupiter:3.6.0'
}
tasks.named('test') {
useJUnitPlatform()
}
Environment Details
Operating System: Windows 11 (64-bit)
Java Version: OpenJDK 17.0.2
Chrome Version: 125.0.6422.113 (Official Build) (64-bit)
ChromeDriver: Version 125.0.6422.78 (downloaded from this link)
Selenium Version: 4.21.0
Issue Description
I am trying to execute a simple Selenium WebDriver script using ChromeDriver, but I encounter the following error:
<code>Exception in thread "main" java.lang.AbstractMethodError: Receiver class org.openqa.selenium.chrome.ChromeDriverService$Builder does not define or inherit an implementation of the resolved method 'abstract java.io.File findDefaultExecutable()' of abstract class org.openqa.selenium.remote.service.DriverService$Builder.
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:437)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:138)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:72)
at Nawa3.Nawa3.service.CrawlingTest.getChromeDriver(CrawlingTest.java:40)
at Nawa3.Nawa3.service.CrawlingTest.main(CrawlingTest.java:47)
<code>Exception in thread "main" java.lang.AbstractMethodError: Receiver class org.openqa.selenium.chrome.ChromeDriverService$Builder does not define or inherit an implementation of the resolved method 'abstract java.io.File findDefaultExecutable()' of abstract class org.openqa.selenium.remote.service.DriverService$Builder.
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:437)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:138)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:72)
at Nawa3.Nawa3.service.CrawlingTest.getChromeDriver(CrawlingTest.java:40)
at Nawa3.Nawa3.service.CrawlingTest.main(CrawlingTest.java:47)
</code>
Exception in thread "main" java.lang.AbstractMethodError: Receiver class org.openqa.selenium.chrome.ChromeDriverService$Builder does not define or inherit an implementation of the resolved method 'abstract java.io.File findDefaultExecutable()' of abstract class org.openqa.selenium.remote.service.DriverService$Builder.
at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:437)
at org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:138)
at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:72)
at Nawa3.Nawa3.service.CrawlingTest.getChromeDriver(CrawlingTest.java:40)
at Nawa3.Nawa3.service.CrawlingTest.main(CrawlingTest.java:47)
What I Have Tried
Ensured that the ChromeDriver path is correctly specified.
Verified the compatibility of ChromeDriver and Chrome browser versions.
Cleaned and rebuilt the project.
Invalidated caches and restarted the IDE.
Despite these steps, the issue persists. Any help or guidance to resolve this would be greatly appreciated.