0
0
Selenium Javatesting~10 mins

Drag and drop in Selenium Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create an Actions object for drag and drop.

Selenium Java
Actions actions = new Actions(driver);
actions.[1](sourceElement, targetElement).perform();
Drag options to blanks, or click blank then click option'
AdragAndDrop
BclickAndHold
CmoveToElement
DdoubleClick
Attempts:
3 left
💡 Hint
Common Mistakes
Using clickAndHold without moveToElement and release causes incomplete drag and drop.
Using doubleClick or moveToElement alone does not perform drag and drop.
2fill in blank
medium

Complete the code to perform drag and drop using clickAndHold, moveToElement, and release.

Selenium Java
Actions actions = new Actions(driver);
actions.[1](sourceElement).moveToElement(targetElement).release().perform();
Drag options to blanks, or click blank then click option'
AdragAndDrop
BdoubleClick
CclickAndHold
DcontextClick
Attempts:
3 left
💡 Hint
Common Mistakes
Using dragAndDrop here would duplicate the action and cause errors.
Using doubleClick or contextClick does not initiate drag and drop.
3fill in blank
hard

Fix the error in the code to correctly perform drag and drop.

Selenium Java
Actions actions = new Actions(driver);
actions.clickAndHold(sourceElement).[1](targetElement).release().perform();
Drag options to blanks, or click blank then click option'
AdragAndDrop
BcontextClick
CdoubleClick
DmoveToElement
Attempts:
3 left
💡 Hint
Common Mistakes
Using dragAndDrop here is incorrect because clickAndHold is already used.
Using doubleClick or contextClick does not move the element.
4fill in blank
hard

Fill both blanks to chain the correct drag and drop actions.

Selenium Java
Actions actions = new Actions(driver);
actions.[1](sourceElement).[2](targetElement).release().perform();
Drag options to blanks, or click blank then click option'
AclickAndHold
BmoveToElement
CdragAndDrop
DdoubleClick
Attempts:
3 left
💡 Hint
Common Mistakes
Using dragAndDrop in the first blank causes syntax errors when chaining.
Using doubleClick does not perform drag and drop.
5fill in blank
hard

Fill all three blanks to create a drag and drop test with proper setup and assertion.

Selenium Java
WebElement source = driver.findElement(By.id("[1]"));
WebElement target = driver.findElement(By.id("[2]"));
new Actions(driver).[3](source, target).perform();
Drag options to blanks, or click blank then click option'
Adraggable
Bdroppable
CdragAndDrop
DclickAndHold
Attempts:
3 left
💡 Hint
Common Mistakes
Using clickAndHold in the last blank requires chaining and is incomplete here.
Mixing up source and target ids causes test failure.