With the below code, I am able to remove only the first product from the cart page but not all the products
public class RemoveProductFromCart {
public static void main(String[] args) throws Exception {
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://askomdch.com/account/");
driver.findElement(By.id("username")).sendKeys("testuser1");
driver.findElement(By.id("password")).sendKeys("Password@123");
driver.findElement(By.xpath("//button[@type='submit' and @name='login']")).click();
Thread.sleep(2000);
Clicking on the cart icon==>
driver.findElement(By.xpath("//div[@id='ast-desktop-header']//div[@class='ast-cart-menu-wrap']")).click();
Thread.sleep(2000);
Grouped all the items to remove into a list and then click them one by one to remove all the products==>
List<WebElement> removeList = driver
.findElements(By.xpath("//table[contains(@class,'shop_table')]//a[@class='remove']"));
for (int i = 0; i < removeList.size(); i++) {
removeList.get(i).click();
Thread.sleep(2000);
if (removeList.size() == 0) {
break;
}
}
}
}