VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-add-chrome-extension-using-python-selenium/

⇱ How to Add Chrome Extension using Python Selenium - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Add Chrome Extension using Python Selenium

Last Updated : 23 Jul, 2025

Introduction

Selenium is a tool for browser automation that supports multiple browsers for testing. With webdriver we can use multiple languages like Python,C#, and Java to write the code for automation testing. For Adding a Chrome extension in a browser with Selenium WebDriver allows us to automate the browser and an extension to it.

Setting Up Selenium with Chrome

pip install selenium pyautogui

Here, we will use pyautogui to press buttons.

Adding Chrome Extension

In the below code, we only need to provide the URL of an extension.

Output:

Adding Local Extension to Chrome using Python Selenium

Steps to Add Chrome Extension

  1. Create new Directory - In which we will have all our extension files
  2. Create a Manifest File - This will be used describe the Extension like Name, version
  3. Create Html File - This will be used to design the interface to show to the user.
  4. Create Javascript file - This will be used to write logical code.
  5. Run the Selenium script to add.

manifest.json

popup.html

popup.js


Add the extension to the Chrome Selenium Script

So this will easily load the extension and then we can use it according to our need.

Output:



Common Debugging Issue

While working with Selenium in chrome we generally have some common issue like Different version of Chrome and Chrome Driver. When we encounter such issue than it will throw error like "SessionNotCreatedException". Also sometime we come across the issues like not getting the element or not able to execute the operation on that element like we cannot send the keys to the button. But some of the common issue can be taken care by following the best practices which we should follow so that we don't encounter such problems while working with selenium.

Best Practices to Follow

Some best practices to follow while working with Selenium.

  1. Keep Tools Updated: Always have the latest version of Chrome Driver, Chrome browser, and Selenium.
  2. Have Virtual Environments: We generally use virtual environment for avoiding dependencies conflicts.
  3. Handle Exceptions: Use try-except blocks to handle exceptions for Code like finding the element or clicking the elements.

Conclusion

Using selenium with chrome we can do so many things. In selenium we have a webdriver which has been used for the automated testing of the website. Here we have used Selenium for adding chrome extension into the chrome. For this we have used python as a language and used pyautogui for clicking on the alerts which are been present in the process.

Comment
Article Tags: