To work efficiently with interactive content like video players and ads one must have a strong command of ActionChains.

What are ActionChains?

ActionChains are a way to automate low level interactions such as mouse movements, mouse button actions, key press, and context menu interactions. This is useful for doing more complex actions like hover over and drag and drop.

ActionChains are kept in a queue, then acted upon once you have all of your interactions in the queue. It's really simple to work with ActionChains, so let's get started.

Working with ActionChains

from selenium import webdriver  
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chome()  

# First, let's define which object we're going to interact with.
element_to_hover_over = driver.find_element_by_id("id_name")

# Next, let's define the interaction we wish to perform.
hover = ActionChains(driver).move_to_element(element_to_hover_over)  
# Finally, perform the hover.

Wrapping Up

In the code above, hover is an object which we add our actions to. Use this same principle to interact with other objects.

© 2017. All Rights Reserved.