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

Chrome: https://sites.google.com/a/chromium.org/chromedriver/downloads

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.
Xpath
Xpath

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 = "https://www.instagram.com/narendramodi/" #You can paste any id
username ="shaurya" #Enter your id
password="test"  #Enter your password
browser.get(followlink)
time.sleep(3)
 
browser.find_element_by_xpath("//a[@class='_l8p4s'][2]").click()
time.sleep(3)
 
a = browser.find_element_by_xpath("//div[@class='_t296e'][1]/div[1]/input[1]")
a.send_keys(username)
 
b = browser.find_element_by_xpath("//div[@class='_t296e'][2]/div[1]/input[1]")
b.send_keys(password)
#How webpage looks before login screenshot
browser.get_screenshot_as_file("Instagram.png")
browser.find_element_by_xpath("//button[@class='_qv64e _gexxb _4tgw8 _njrw0']").click()
#How webpage looks after login screenshot
browser.get_screenshot_as_file("Instagram1.png")
time.sleep(2)
browser.get(url)

One thought on “Python Selenium | Instagram Login

Add yours

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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.

Powered by WordPress.com.

Up ↑

%d bloggers like this: