JS Testing Academy · QA Demo Site

Sortable

Reorder a list by dragging. Checking the order after the drag is the real exercise here.

Drag the items to reorder them.

  • One
  • Two
  • Three
  • Four
  • Five

Practice tasks

  1. Read the starting order of the list and store it.
  2. Drag One below Three and assert the new order.
  3. Assert the order shown in the output matches the DOM order.
  4. Click Reset and assert the original order is back.
  5. Drag the last item to the first position and assert it moved.
Sample automation code
Actions actions = new Actions(driver);
WebElement first = driver.findElement(By.cssSelector("#sortable-list li:nth-child(1)"));
WebElement third = driver.findElement(By.cssSelector("#sortable-list li:nth-child(3)"));
actions.clickAndHold(first).moveToElement(third).release().perform();

List<WebElement> items = driver.findElements(By.cssSelector("#sortable-list li"));
Assert.assertEquals(items.get(0).getText(), "Two");