Selenium + Python · Lesson 22 of 43
Module 22: Mouse & Keyboard Actions
Your task
Implement hover_and_click(driver, hover_elem, click_elem):
Write it in the editor, then press Check answer (Ctrl + Enter).
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
menu = driver.find_element(By.ID, "nav-menu")
actions.move_to_element(menu).perform()
# Drag and drop:
source = driver.find_element(By.ID, "draggable")
target = driver.find_element(By.ID, "droppable")
actions.drag_and_drop(source, target).perform()Complex hardware gestures like hovering over navigation flyouts, right-clicking, and drag-and-drop are performed using ActionChains in Python. In this lesson, you will chain actions and execute them using perform(). Let's master ActionChains!
Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.
You forgot to call .perform() at the end! Without .perform(), actions remain queued in memory.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___