Python Selenium
About Lesson

In this Python Selenium tutorial we are going to learn about Python Selenium Action Chains, so we have learned some basic actions on Python selenium,  for example we have learned that how you can click on a button in a web page or how you can write a text on textbox or input field, how ever some times we need to perform multiple actions for example keeping the Shift button pressed and typing text for uppercase letters, or dragging and dropping mouse actions. so for these actions also we can call action chains,  Selenium Action Chains are a ways provided by Selenium to automate low level interactions with website such as mouse movements, mouse button actions, key press, and context menu(right click menu) interactions. These special methods are useful for doing more complex actions like mouse over and drag and drop that are not possible by direct webdriver actions.

 

 

OK now this is the complete code for this lesson.

 

 

First we need to import our web driver and action chains classes.

 

 

 

After that we are going to open our Chrome Driver and go to specific website.

 

 

Now we want to find the web elements locator and we are using the XPath locator.

 

 

After that we want to add our all web elements and driver in the selenium action chains.

 

 

 

Run the complete code and you will see that after opening the website it will choose the four elements from the list.

Python Selenium Action Chains
Python Selenium Action Chains

 

 

 

 

OK now let’s create our second example, in this example we want to hold CTRL key with our actions. so first of all we need a web page to do our automation, we are using a code from JqueryUI and it is selectable code, you can get the code from their or you can just create an html file and add this code, and you can see that we have added name attributes for our five items in the list, because we want to select these five items, and we want to use the find_element_by_name() locator from selenium.

 

 

 

This is the Python code for the second example, it is the same as the above code, but we have just used key_down(keys.Keys.CONTROL) in here, because by clicking the items i want to hold the CTRL key.

 

 

 

Run the code and this is the result.

python-selenium-actions-chains-example
python-selenium-actions-chains-example

 

Thank you for visiting my website! If you enjoyed the free courses, please consider supporting my works on Patreon.
Exercise Files
No Attachment Found
No Attachment Found