E-Commerce-Website-Automation [Selenium + Python]

Alexander Schlee
3 min readMar 1, 2021

The following article will simulate and automate a purchase scenario within an E-Commerce- Website using Selenium & Python. The website itself is designed for practice purposes.

The following imports are required for this simple project:

Imports required at the beginning

This short article should demonstrate how to interact with different elements in Selenium, like Dropdowns, Buttons, Checkboxes, Textboxes, Calendars etc.

The goal is to buy different electronic devices (2x iPhones + 1x Laptop) , select the delivery date and complete the checkout process.

We have to select the necessary HTML-elements with Selenium WebDriver and interact with them.

To choose an iPhone, we have to find the HTML snippet where the information is stored:

Now we have the possibility to write the X-Path expression and click on the element:

X-Path expression to select the iPhone

After selecting the device, we need to choose the quantity and put it in out cart:

We have now the possibility to create two X-Path expressions, one for the quantity (2 pieces) and one for adding the products in our cart:

change quantity and add to cart

The same logic and procedure can be applied to select our second device (1x Laptop).

After we have selected all items, we need to choose the delivery date. Therefore, its mandatory to interact with the calendar.

The default Delivery Date is 2011–04–22. Let’s say we want the products to be delivered on 2022–12–31. To achieve this, the following steps have to be done in our code:

After adding our items to the cart, we have to complete the checkout process by providing our credentials etc.:

Credentials during the checkout process

We can see that we have two different elements (regular textboxes, highlighted in red + dropdowns, highlighted in green). That means we have to figure out how to interact with these elements while writing our code. To work with the Dropdowns, we need to import the Select Class upfront.

interacting with textboxes and dropdowns

Finally, we need to accept the terms & conditions and click on the confirmation checkbox and finally on the Continue Button:

accepting the terms & conditions
code snippet fot the terms & conditions and continue

After we have clicked through the ckeckout page, we receive finally the success message :

Success Notification

This was a short overview over the entire project. If you are interested in the step by step tutorial of this project, check out the video version on Youtube:

Links:

--

--

Alexander Schlee

Python Enthusiast | IT- Consultant | Focussing on projects related to Data Science and Testautomation