How to simulate HTML5 Drag and Drop in Selenium Webdriver?

We can simulate HTML5 drag and drop with Selenium webdriver. This is a feature that gets implemented if an element is dragged from its position and dropped on another element in another position.

Actions class in Selenium is used for taking care of this functionality. The drag_and_drop(source, target) is the available method under Actions class for carrying out this task. We have to import from selenium.webdriver import ActionChains to our code to use this method of Actions class.

Let us take the two elements and try to drag the first element on to the second element.


from selenium.webdriver import ActionChains
from selenium import webdriver
   driver = webdriver.Chrome (executable_path="C:\chromedriver.exe")
   # identify source and destination elements
   # action object creation
   a = ActionChains(driver)