Automate login to Gmail, Facebook, Instagram, LinkedIn and Tumblr using selenium with Python

Create Virtualenv with Python3 in Linux, Ubuntu or MAC

virtualenv env -p python3

Create Virtualenv with Python3 in Windows:

python -m venv env

Activate Virtualenv in Linux, Ubuntu or MAC:

source env/bin/activate

Activate Virtualenv in Windows:

.\env\Scripts\activate

Install selenium module with pip command:

pip3 install selenium

Update requirements.txt file:

pip3 freeze > requirements.txt

Download geckodriver:

To download geckodriver for Windows,Linux and Mac:

https://github.com/mozilla/geckodriver/releases/tag/v0.26.0

Extract the zip/tar file and put it in the root repository where your .py script exists.

Create a python script:

vim script.py

Facebook:-

from selenium import webdriver

import time

driver = webdriver.Firefox(executable_path=’./geckodriver’)

driver.get (‘https://www.facebook.com')

driver.find_element_by_id(‘email’).send_keys(‘<yourid>’)

driver.find_element_by_id(‘pass’).send_keys(‘<yourpassword>’)

driver.find_element_by_id(‘loginbutton’).click()

Gmail:-

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

from selenium.webdriver.common.by import By

import time

driver = webdriver.Firefox(executable_path=’./geckodriver’)

driver.get(‘http://gmail.com')

driver.find_element_by_id(“identifierId”).send_keys(‘<yourlid>’)

driver.find_element_by_id(“identifierNext”).click()

time.sleep(1)

driver.find_element_by_name(“password”).send_keys(‘<yourpassword>’)

driver.find_element_by_id(“passwordNext”).click()

LinkedIn:-

from selenium import webdriver

driver = webdriver.Firefox(executable_path=’./geckodriver’)

driver.get(‘https://www.linkedin.com/login')

username = driver.find_element_by_id(‘username’)

username.send_keys(‘<yourid>’)

password = driver.find_element_by_id(‘password’)

password.send_keys(‘<yourpassword>’)

log_in_button = driver.find_element_by_class_name(‘login__form button’)

log_in_button.click()

Instagram:-

from selenium import webdriver

import time

browser = webdriver.Firefox(executable_path=’./geckodriver’)

url = “https://www.instagram.com/"

username =”<yourid>”

password=”<yourpassword>”

browser.get(url)

time.sleep(3)

a = browser.find_element_by_name(“username”)

a.send_keys(username)

b = browser.find_element_by_name(“password”)

b.send_keys(password)

log_in_button = browser.find_element_by_class_name(‘y3zKF’)

log_in_button.click()

Tumblr:-

from selenium import webdriver
import time

driver = webdriver.Firefox(executable_path=’./geckodriver’)
driver.get(‘https://www.tumblr.com/login')

username = driver.find_element_by_id(“signup_determine_email”)
username.send_keys(“<yourid>”)

driver.find_element_by_id(“signup_forms_submit”).click()
time.sleep(3)
driver.find_element_by_link_text(“Use password to log in”).click()

password = driver.find_element_by_id(“signup_password”)
password.send_keys(“<yourpassword>”)

driver.find_element_by_id(“signup_forms_submit”).click()

--

--

--

DevOps Engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

How to store translations inside a database with Globalize

Perform Foundational Infrastructure Tasks in Google Cloud: Challenge Lab

My first Streamlit app using choropleth map

CS373 Spring 2022: Luca Santos

How to deploy KIRA Network Infrastructure on Google Cloud

Flip String to Monotone Increasing in O(n) time

From SVN repository to Git repository

Project to make Clone of Freshly- An E-commerce of Food

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Parth Vijay

Parth Vijay

DevOps Engineer

More from Medium

Getting started with WebDriver IO v7

JMeter — set up Selenium WebDriver Sampler (basic steps)

Locators in Selenium

Key concepts for app test automation