Challenge - 5 Problems
Drag and Drop Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the result of this drag and drop Selenium code?
Consider the following Selenium Java code snippet that performs a drag and drop action. What will be the output if the drag and drop is successful?
Selenium Java
WebElement source = driver.findElement(By.id("drag-source")); WebElement target = driver.findElement(By.id("drop-target")); Actions actions = new Actions(driver); actions.dragAndDrop(source, target).perform(); System.out.println(target.getText());
Attempts:
2 left
💡 Hint
Think about what happens to the target element's text after a successful drag and drop.
✗ Incorrect
The dragAndDrop method moves the source element onto the target. After performing, the target's text usually changes to reflect the dropped item. So printing target.getText() shows the updated text.
❓ locator
intermediate2:00remaining
Which locator is best for identifying draggable and droppable elements?
You want to automate drag and drop in Selenium Java. Which locator strategy is best practice for identifying the source and target elements?
Attempts:
2 left
💡 Hint
IDs are unique and fastest to locate.
✗ Incorrect
Using By.id is best because IDs are unique, fast, and reliable locators. XPath and class names can be less stable or slower. CSS nth-child is fragile and depends on page structure.
❓ assertion
advanced2:00remaining
Which assertion correctly verifies a successful drag and drop?
After performing drag and drop, you want to assert that the target element contains the text "Dropped!". Which assertion is correct in JUnit?
Attempts:
2 left
💡 Hint
You want to check exact text equality.
✗ Incorrect
assertEquals checks that the target's text exactly matches "Dropped!" which confirms success. assertTrue with contains is less strict. assertFalse and assertNull are incorrect here.
🔧 Debug
advanced2:00remaining
Why does this drag and drop code fail with ElementNotInteractableException?
Given this code snippet, the drag and drop fails with ElementNotInteractableException. What is the most likely cause?
Selenium Java
WebElement source = driver.findElement(By.id("drag-source")); WebElement target = driver.findElement(By.id("drop-target")); Actions actions = new Actions(driver); actions.clickAndHold(source).moveToElement(target).release().perform();
Attempts:
2 left
💡 Hint
ElementNotInteractableException means element cannot be interacted with currently.
✗ Incorrect
This exception usually means the source element is hidden, disabled, or overlapped, so Selenium cannot interact with it. The locator is found, Actions supports clickAndHold, and perform() is present.
❓ framework
expert3:00remaining
In a Selenium Java test framework, where should drag and drop logic be placed for best design?
You are designing a Selenium Java test framework. Where is the best place to put the drag and drop code for reusability and maintainability?
Attempts:
2 left
💡 Hint
Think about the Page Object Model design pattern.
✗ Incorrect
Placing drag and drop logic inside the Page Object class keeps tests clean and encapsulates page behavior. Utility classes are less ideal for actions tied to specific pages. Test methods and main methods should not contain detailed UI interaction code.