I am using chrome driver version 2.35 in 2023, Why old chromedriver version? That's because my project using Chrome Extension Framework (CEF) project.
Using maven project
IDE --> Intellij 2022.1.3 my pom.xml file:
<dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.7.2</version> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <version>7.10.1</version> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-junit</artifactId> <version>7.10.1</version> </dependency>
3.My code :
public static ChromeDriver driver;
public static WebDriverWait wait;
public static JavascriptExecutor jse;
public static Actions builder;
public static Action test;
public static void main(String[] args) throws InterruptedException , Throwable {
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
chromeOptions.setExperimentalOption("debuggerAddress", "localhost:8003");
driver = new ChromeDriver(chromeOptions);
builder = new Actions(driver);
WebElement fromElement = driver.findElement(By.xpath("//img[@class='rounded-circle' and ./following-sibling::p[text()='Pendidikan']]"));
WebElement fromElementPensiun = driver.findElement(By.xpath("//img[@class='rounded-circle' and ./following-sibling::p[text()='Pensiun']]"));
WebElement fromElement2 = driver.findElement(By.xpath("//*[@id='bag2']/div[3]"));
WebElement toElement = driver.findElement(By.xpath("//div[@id='bag1']"));
Action dragAndDrop = builder.clickAndHold(fromElementPensiun)
.moveToElement(toElement)
.release(toElement)
.build();
Thread.sleep(2000);
dragAndDrop.perform();
Thread.sleep(2000);