22. ActionChains: Mouse Hover, Context Clicks & Drag and Drop

Chaining Actions in Python

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()

Task

  • Implement hover_and_click(driver, hover_elem, click_elem):
  • 1. ActionChains(driver).move_to_element(hover_elem).click(click_elem).perform().
πŸ’‘Common doubts
Did you like the problem?
Lesson 22 of 43
Python
Loading code editor…
Next