DEV Community

loading...
Cover image for Instagram Login Automation using Selenium

Instagram Login Automation using Selenium

ShubhamTiwari909
Newbiew developer
・2 min read

Hello Everyone today i will show you a simple instagram Login automation in Python using selenium.

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.

A browser-driver then executes these scripts on a browser-instance on your device.

Firstly execute this command in your terminal -

pip install selenium
Enter fullscreen mode Exit fullscreen mode

Lets get dive into the code -

from selenium import webdriver
from time import sleep

browser = webdriver.Chrome("D:\old pc\Softwares\chromedriver_win32\chromedriver")

browser.implicitly_wait(1)

browser.get('https://www.instagram.com/')

sleep(1)

username_input = browser.find_element_by_css_selector("input[name='username']")
password_input = browser.find_element_by_css_selector("input[name='password']")

username_input.send_keys("your_username")
password_input.send_keys("your_password")

login_button = browser.find_element_by_xpath("//button[@type='submit']")
login_button.click()

sleep(9999999)

browser.close()
Enter fullscreen mode Exit fullscreen mode

1.First we have imported selenium and time module.
2.Then after that we access the chrome browser using Chrome drivers.
3.Then we provided the instagram page login page link in the get method.
4.sleep(1) means one second of pause then continue.
5.Then we find the input fields using css selectors.
6.Then we provide username and password.
7.Then we find the login button using xpath where we provide the html tagname and inside it we provide the attribute and its value.
8.Then we use click() method to click the login button automatically.
9.sleep(99999999) means the browser wont close.

I am a newbie developer and still exploring.
So, if you find any mistake in the post please highlight it in the comment section.
THANK YOU FOR READING THIS POST.

Chrome driver - https://chromedriver.chromium.org/downloads

If you want to learn more about selenium then visit here-
https://www.browserstack.com/selenium

Discussion (0)