0
0
Selenium Javatesting~20 mins

Drag and drop in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Drag and Drop Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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());
AThe text of the target element after the drag and drop, reflecting the dropped item
BThe text of the source element before drag and drop
CAn exception is thrown because dragAndDrop requires clickAndHold
DThe text of the target element remains unchanged
Attempts:
2 left
💡 Hint
Think about what happens to the target element's text after a successful drag and drop.
locator
intermediate
2: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?
ABy.id("drag-source") and By.id("drop-target")
BBy.xpath("//div[@class='draggable']") and By.xpath("//div[@class='droppable']")
CBy.className("drag") and By.className("drop")
DBy.cssSelector("div:nth-child(1)") and By.cssSelector("div:nth-child(2)")
Attempts:
2 left
💡 Hint
IDs are unique and fastest to locate.
assertion
advanced
2: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?
AassertNull(target.getText());
BassertTrue(target.getText().contains("Dropped!"));
CassertFalse(target.getText().equals("Dropped!"));
DassertEquals("Dropped!", target.getText());
Attempts:
2 left
💡 Hint
You want to check exact text equality.
🔧 Debug
advanced
2: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();
AThe target element locator is incorrect causing NoSuchElementException
BThe source element is not visible or not enabled for interaction
CThe Actions class does not support clickAndHold method
DThe perform() method is missing at the end
Attempts:
2 left
💡 Hint
ElementNotInteractableException means element cannot be interacted with currently.
framework
expert
3: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?
ADirectly inside the test method where drag and drop is needed
BInside a utility/helper class with static methods for drag and drop
CInside the Page Object class representing the page containing draggable elements
DIn the main method of the test suite class
Attempts:
2 left
💡 Hint
Think about the Page Object Model design pattern.