Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Webscraping
  • Beautiful Soup
  • Request
  • Scrapy
  • open cv
  • Data analysis
  • Machine learning
  • NLP
  • Deep learning
  • Data Science
  • Interview question
  • ML math
  • ML Projects
  • ML interview
  • DL interview
Open In App
Next Article:
Fetch top 10 starred repositories of user on GitHub | Python
Next article icon

How to create GitHub repository using Python Selenium?

Last Updated : 21 Oct, 2021
Comments
Improve
Suggest changes
Like Article
Like
Report

Prerequisite: Selenium

Selenium is a powerful tool for controlling web browsers through programs and performing browser automation. It is functional for all browsers, works on all major OS and its scripts are written in various languages i.e Python, Java, C#, etc, we will be working with Python. Selenium Tutorial covers all topics such as – WebDriver, WebElement, Unit Testing with selenium. This Python Selenium Tutorial covers Selenium from basics to advanced and professional uses.

In this article, we will write a python script that will create a GitHub repository using selenium in Python

Steps for creating a GitHub repository:

  • Before creating a repository, we need to login first (Require username and password).
  • After Login, we will go for creating a new repository, and then we require the repository name.
  • After this, three things are left; descriptions, mode(Private or Public), and readme file.

Step-by-step Approach:

Step 1: Import module and create Chrome Object

Python3
# import Module from selenium import webdriver  # Create Chrome Object driver = webdriver.Chrome(     'Chrome Driver Path') 

 
 

Step 2: Create github_repo() with the following arguments to access user GitHub with suitable parameters and perform required tasks.

Python3
def github_repo(user_name, pass_word,                  repository_name, descriptions=False,                 private=False, readme=False):          # Open github login page     driver.get('https://github.com/login')      # Username     username = driver.find_element_by_xpath('//*[@id="login_field"]')     username.send_keys(user_name)      # Password     password = driver.find_element_by_xpath('//*[@id="password"]')     password.send_keys(pass_word)      # Click on sign in button     signin = driver.find_element_by_xpath(         '//*[@id="login"]/div[4]/form/input[14]')     signin.click()      # Create new repo.     new_repo = driver.find_element_by_xpath('//*[@id="repos-container"]/h2/a')     new_repo.click()      # Enter Repo. name     repositoryname = driver.find_element_by_xpath('//*[@id="repository_name"]')     repositoryname.send_keys(repository_name)      # Optional      # Enter Description     if descriptions:         description = driver.find_element_by_xpath(             '//*[@id="repository_description"]')         description.send_keys(descriptions)      # Private Mode     if private:         private = driver.find_element_by_xpath(             '//*[@id="repository_visibility_private"]')         private.click()      # Create ReadMe File     if readme:         readme = driver.find_element_by_xpath(             '//*[@id="repository_auto_init"]')         readme.click() 

Step 3: Call the above function with suitable parameters in the driver code to create a GitHub repository.

Python3
github_repo("Enter Usename", "Enter Password",              "Repository name") 

Below is the Implementation:

Python3
# import Module from selenium import webdriver  # Create Chrome Object driver = webdriver.Chrome('Chrome Driver Path')   def github_repo(user_name, pass_word,                  repository_name, descriptions=False,                 private=False, readme=False):          # Open github login page     driver.get('https://github.com/login')      # Username     username = driver.find_element_by_xpath('//*[@id="login_field"]')     username.send_keys(user_name)      # Password     password = driver.find_element_by_xpath('//*[@id="password"]')     password.send_keys(pass_word)      # Click on signin button     signin = driver.find_element_by_xpath(         '//*[@id="login"]/div[4]/form/input[14]')     signin.click()      # Create new repo.     new_repo = driver.find_element_by_xpath('//*[@id="repos-container"]/h2/a')     new_repo.click()      # Enter Repo. name     repositoryname = driver.find_element_by_xpath('//*[@id="repository_name"]')     repositoryname.send_keys(repository_name)      # Optional      # Enter Description     if descriptions:         description = driver.find_element_by_xpath(             '//*[@id="repository_description"]')         description.send_keys(descriptions)      # Private Mode     if private:         private = driver.find_element_by_xpath(             '//*[@id="repository_visibility_private"]')         private.click()      # Create ReadMe File     if readme:         readme = driver.find_element_by_xpath(             '//*[@id="repository_auto_init"]')         readme.click()   github_repo("Enter Usename", "Enter Password",              "Repository name")  print("Repository created")  create_repo = driver.find_element_by_xpath(     '//*[@id="new_repository"]/div[4]/button')  create_repo.click() 

Output:


Next Article
Fetch top 10 starred repositories of user on GitHub | Python
author
abhigoya
Improve
Article Tags :
  • Python
  • Software Testing
  • Selenium
  • Python-selenium
  • Python Selenium-Exercises
Practice Tags :
  • python

Similar Reads

  • How to Add Chrome Extension using Python Selenium
    IntroductionSelenium 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
    6 min read
  • Fetch top 10 starred repositories of user on GitHub | Python
    Prerequisites: Basic understanding of python, urllib2 and BeautifulSoup We often write python scripts to make our task easier, so here is the script which helps you to fetch top 10 starred repositories of any user on GitHub.You just need Github username (For example: msdeep14) to run the script.Scri
    4 min read
  • How to Locate Elements using Selenium Python?
    Selenium: is an open-source tool that automates web browsers. It provides a single interface that lets you write test scripts in programming languages like Ruby, Java, NodeJS, PHP, Perl, Python, and C#, among others. I personally prefer Python as it’s very easy to write code in python. A browser-dri
    3 min read
  • How do I Pass Options to the Selenium Chrome Driver using Python?
    An open-source automation tool that helps in controlling browsers without any human intervention is known as Selenium. It is mostly used for testing purposes. For smoothing the testing through Selenium, we can use options available in Selenium that help in testing in the background, disabling extens
    4 min read
  • How to install a Python Package from a GitHub Repository
    In this article we will learn how to install a pip package from a git repository, PIP supports installing from various version control systems (VCS). This support requires a working executable to be available (for the version control system being used). It is used through URL prefixes: Git -- git+ M
    2 min read
  • How to scrape multiple pages using Selenium in Python?
    As we know, selenium is a web-based automation tool that helps us to automate browsers. Selenium is an Open-Source testing tool which means we can easily download it from the internet and use it. With the help of Selenium, we can also scrap the data from the webpages. Here, In this article, we are g
    4 min read
  • Get all text of the page using Selenium in Python
    As we know Selenium is an automation tool through which we can automate browsers by writing some lines of code. It is compatible with all browsers, Operating systems, and also its program can be written in any programming language such as Python, Java, and many more. Selenium provides a convenient A
    3 min read
  • How to check if an element exists with Python Selenium?
    Selenium is one of the most powerful and widely used tools for web automating web applications. Whether you're a software developer or a QA tester, Selenium is an important tool to have in your toolkit. Selenium is widely used for automating user interactions like clicking buttons, filling out the f
    7 min read
  • execute_script driver method - Selenium Python
    Selenium’s Python Module is built to perform automated testing with Python. Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. To open a webpage using Selenium Python, checkout – Navigating links using get method – Selenium Python. Just bein
    2 min read
  • How to click a button on webpage using Selenium?
    This article is all about how to click any button using Selenium on a webpage and many more concepts related to the same which are discussed below. Table of Content What is Selenium? How to click on a button using Selenium Conclusion Frequently Asked Questions on How to click a button on webpage usi
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences