0
0
Selenium Pythontesting~10 mins

Click and hold in Selenium Python - Interactive Code Practice

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

Complete the code to perform a click and hold action on the element.

Selenium Python
from selenium.webdriver import ActionChains

actions = ActionChains(driver)
element = driver.find_element(By.ID, 'button')
actions.[1](element).perform()
Drag options to blanks, or click blank then click option'
Acontext_click
Bclick_and_hold
Cdouble_click
Dclick
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'click' instead of 'click_and_hold' which only clicks without holding.
Using 'double_click' which clicks twice quickly.
Using 'context_click' which opens the right-click menu.
2fill in blank
medium

Complete the code to release the mouse button after click and hold.

Selenium Python
actions.click_and_hold(element).[1]().perform()
Drag options to blanks, or click blank then click option'
Arelease
Bdouble_click
Cclick
Dcontext_click
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'click' which clicks but does not release the hold properly.
Using 'double_click' which clicks twice.
Using 'context_click' which right-clicks.
3fill in blank
hard

Fix the error in the code to correctly perform click and hold on an element located by CSS selector.

Selenium Python
element = driver.find_element(By.[1], '#drag')
actions = ActionChains(driver)
actions.click_and_hold(element).perform()
Drag options to blanks, or click blank then click option'
Acss
BcssSelector
CCSS
Dcss_selector
Attempts:
3 left
💡 Hint
Common Mistakes
Using camelCase like 'cssSelector' which is invalid in Selenium Python.
Using uppercase 'CSS' which is not recognized.
Using 'css' which is incomplete.
4fill in blank
hard

Fill both blanks to create a drag and drop action using click and hold, move to element, and release.

Selenium Python
source = driver.find_element(By.ID, 'source')
target = driver.find_element(By.ID, 'target')
actions = ActionChains(driver)
actions.[1](source).[2](target).release().perform()
Drag options to blanks, or click blank then click option'
Aclick_and_hold
Bclick
Cmove_to_element
Dcontext_click
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'click' instead of 'click_and_hold' which does not hold the mouse button.
Using 'context_click' which right-clicks instead of dragging.
Not moving to the target element before releasing.
5fill in blank
hard

Fill all three blanks to create a test that clicks and holds an element, waits 2 seconds, then releases.

Selenium Python
import time

button = driver.find_element(By.CLASS_NAME, '[1]')
actions = ActionChains(driver)
actions.[2](button).perform()
time.[3](2)
actions.release().perform()
Drag options to blanks, or click blank then click option'
Aclickable-button
Bclick_and_hold
Csleep
Dclick
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'click' instead of 'click_and_hold' which does not hold the mouse button.
Using wrong class name or locator.
Not waiting before releasing.