Python Selenium | Instagram Login

Selenium: Selenium Python bindings provide a convenient API to access Selenium Web Driver like Firefox, Chrome, etc.

What is webdriver?
Selenium WebDriver is an automation testing tool. When I say automation, it means it automates test scripts written in Selenium.

Webdriver Install


Library Imported

from selenium import webdriver
import time

Before we start lets see what is Xpath.
XPath :XPath stands for XML Path Language, used to find an element in a webpage. You can easily find it using inspect element.

Instagram Login within seconds & How to take screenshots

from selenium import webdriver     
# For using sleep function because selenium 
# works only when the all the elemets of the 
# page is loaded.
import time
browser = webdriver.Chrome("C:\Program Files (x86)\Google\Chrome\chromedriver.exe") 
url = "" #You can paste any id
username ="shaurya" #Enter your id
password="test"  #Enter your password
a = browser.find_element_by_xpath("//div[@class='_t296e'][1]/div[1]/input[1]")
b = browser.find_element_by_xpath("//div[@class='_t296e'][2]/div[1]/input[1]")
#How webpage looks before login screenshot
browser.find_element_by_xpath("//button[@class='_qv64e _gexxb _4tgw8 _njrw0']").click()
#How webpage looks after login screenshot

3 thoughts on “Python Selenium | Instagram Login

Add yours

  1. Nice post Shaurya. I use this package called InstaPy. It’s written using Selenium and is very easy to use for Instagram. You have inbuilt functions to perform most activities.


Leave a Reply to Abhirath Mahipal Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Website Powered by

Up ↑

%d bloggers like this: