🚀 Getting Started with Python for Selenium Automation – Installations, Setup & Best Practices (Beginner Guide)


 🚀 Getting Started with Python for Selenium Automation – From Beginner to Pro (Part 2)


Welcome back, friends! In the first blog, we explored what automation testing is, the role Selenium plays, and why Python is a smart choice for beginners and pros alike. If you haven’t checked it out, read it here, but..........

🔙 Previously in this Series: Part 1 – "What is Automation Testing and Why is it Important?" (Published on July 6, 2025)
(Search "Blog 1: What is Automation Testing" on this site to read it)

Now that we’re aligned with the “why”, let’s dive into the how.

This post will walk you through:

  • Installing Python the right way

  • Setting up your development environment

  • Installing Selenium

  • Writing your first test

  • Structuring your project using GitHub

  • Best practices for beginners

Let’s start building your automation journey!



🐍 Step 1: Install Python (Latest Version Recommended)

👉 Why Python for Selenium?

🔧 How to Install Python:
python --version

Python is clean, readable, has great community support, and works beautifully with Selenium for test automation.

  1. Go to https://www.python.org/downloads

  2. Download the latest version (Python 3.10+ is preferred)

  3. During installation, check “Add Python to PATH”

  4. Verify installation via terminal/command prompt:

💡 Pro Tip: Use pyenv for managing multiple Python versions if you’re a Linux or Mac user.



💻 Step 2: Set Up Your Development Environment

Let’s make sure your environment is neat and organised.

🧰 Recommended Tools:

  • VS Code – Lightweight and feature-rich (Download)

  • Git – Version control (Download)

  • GitHub – Store your test scripts online (Repo)

  • Python Virtual Environment – Keeps dependencies clean

Create a New Project Folder:


mkdir selenium_automation cd selenium_automation python -m venv venv source venv/bin/activate # or venv\Scripts\activate on Windows



📦 Step 3: Install Selenium

Now let’s bring in the hero of our story.


pip install selenium

Verify it works:

python >>> import selenium >>> print(selenium.__version__)

You’re now officially a Selenium user!



🌐 Step 4: Install WebDriver (Chrome/Edge/Firefox)

Selenium needs a driver to communicate with the browser.

🔹 For Chrome:

  1. Check your Chrome version:
    Menu → Help → About Chrome

  2. Download ChromeDriver matching your version

  3. Add it to your system PATH

Optional: Use webdriver_manager To skip manual steps:


pip install webdriver-manager

Example usage:


from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome(ChromeDriverManager().install())


✍️ Step 5: Your First Automation Script

Let’s open Google and search for something using Python & Selenium:


from selenium import webdriver from selenium.webdriver.common.by import By from webdriver_manager.chrome import ChromeDriverManager import time driver = webdriver.Chrome(ChromeDriverManager().install()) driver.get("https://www.google.com") search = driver.find_element(By.NAME, "q") search.send_keys("Selenium with Python") search.submit() time.sleep(3) driver.quit()

Congrats 🎉, you’ve automated a Google search!



📁 Step 6:Organisee Code with GitHub

Your code deserves a home. Create a repository on GitHub:
🔗 https://github.com/kuro-shiv/Automation_Selenium_Python

Basic Git Commands:


git init git remote add origin
https://github.com/kuro-shiv/Automation_Selenium_Python.git git add . git commit -m "Initial commit with setup and first script" git push -u origin master

Keeping everything on GitHub ensures:

  • Version control

  • Collaboration

  • Visibility for job portfolios



🧠 Best Practices for Beginners

  1. ✅ Always use a virtual environment

  2. ✅ Keep scripts modular (one function = one action)

  3. ✅ Comment your code

  4. ✅ Use proper waits instead of time.sleep() Later (we’ll cover this)

  5. ✅ Use .gitignore to avoid uploading sensitive files

  6. ✅ Log test results (we’ll cover unittest and pytest soon)



🔄 What’s Next in Blog #3?

Here’s a sneak peek into the next post:

  • Learn how to locate web elements using advanced techniques

  • Understand the different locator strategies (ID, Name, XPath, CSS Selector, etc.)

  • Build a mini form test case



🎁 Bonus Tip: Speed Boost with VS Code Extensions

  • Python by Microsoft

  • Pylance for IntelliSense

  • GitLens for Git visualisation

  • Jupyter (if you're planning to write in notebooks)



✅ Conclusion

In this second step of your Selenium automation journey, we’ve laid a strong foundation by understanding the core architecture of Selenium and how it interacts with browsers. You’ve now set up your environment, installed Selenium, and written your first Python script to automate a browser—huge progress already!

Remember: becoming a Selenium pro isn’t just about writing test cases—it’s about understanding the flow, learning best practices, and building reusable, maintainable scripts. In upcoming blogs, we’ll dive into advanced interactions like working with dynamic elements, handling popups, performing end-to-end test scenarios, and integrating with test frameworks like PyTest or unittest.

Keep experimenting, play around with different websites, and try modifying your script. The more you break it, the more you'll learn.

Stay tuned, stay curious — and don’t forget to ⭐ star the GitHub repo for updates and code.


🙌 Final Thoughts

You’ve now taken a solid step toward becoming a Selenium Automation Tester using Python. The setup phase is boring for some, but it’s the foundation of everything pro-level.

Stay tuned for the next post! And don’t forget to:

✅ Star the GitHub Repo
✅ Share this blog with your friends
✅ Drop your questions or suggestions in the comments



🔗 Helpful Links




Comments

Popular posts from this blog

How to Build Your First Machine Learning Model: Step-by-Step Beginner Guide

Understanding Machine Learning: Basics, Types, and Applications

🚀 What is Automation Testing? Learn Selenium with Python (Beginner Guide)